Exemplo n.º 1
0
 def _panels(self, context):
     if not context.panels():
         return None
     g = self._generator
     req = context.req()
     panels = context.panels()
     if not panels:
         return None
     result = []
     for panel in panels:
         title = g.a(panel.title(), name='panel-' + panel.id() + '-anchor', tabindex=0,
                     cls='panel-anchor')
         titlebar_content = panel.titlebar_content()
         if titlebar_content:
             title += titlebar_content.export(context)
         channel = panel.channel()
         if channel:
             # Translators: ``RSS channel'' is terminology idiom, see Wikipedia.
             # The placeholder %s is replaced by channel title.
             channel_title = _("RSS channel %s") + ' ' + panel.title()
             title += g.a(g.span('', cls='feed-icon'),
                          href=channel, aria_label=channel_title, title=channel_title,
                          type='application/rss+xml', cls='feed-link')
         content = panel.content()
         # Add a fake container to force the heading level start at 4.
         lcg.Container(lcg.Section('', lcg.Section('', content)))
         result.append(g.div((g.h3(title),
                              g.div(content.export(context), cls='panel-content')),
                             id='panel-' + self._safe_css_id(panel.id()), cls='panel',
                             role='complementary',
                             aria_label=panel.accessible_title()))
     extra_content = context.application.right_panels_bottom_content(req)
     if extra_content:
         result.append(g.div(extra_content.export(context), cls='panels-bottom-content'))
     return result
Exemplo n.º 2
0
 def authoring(cls):
     content = [lcg.p(p) for p in cls._HELP_INTRO]
     if cls._SOURCE_FORMATTING:
         content.append(
             lcg.Section(title=_("Exercise Definition"),
                         content=[lcg.p(p)
                                  for p in cls._SOURCE_FORMATTING]))
     if cls._SOURCE_EXAMPLE:
         content.append(
             lcg.Section(title=_("Definition Example"),
                         content=lcg.pre(cls._SOURCE_EXAMPLE.strip())))
     return lcg.Section(title=cls.name(), content=content)
Exemplo n.º 3
0
    def _spec_help_content(self, spec_name):
        if not pytis.form.has_access(spec_name):
            return (_("Access Denied"),
                    lcg.p(_("You don't have permissions for specification „%s“.") % spec_name))
        resolver = pytis.util.resolver()
        try:
            view_spec = resolver.get(spec_name, 'view_spec')
        except pytis.util.ResolverError:
            return None, None

        def field_label(f):
            label = f.column_label()
            if not label:
                label = f.label() or f.id()
            elif f.label() and f.label() != label:
                label += ' (' + f.label() + ')'
            return label

        def field_description(f):
            result = self._description('field', spec_name, f.id(), f.descr())
            related_specnames = [name for name in
                                 [f.codebook()] + [link.name() for link in f.links()] if name]
            if related_specnames:
                pytis.util.remove_duplicates(related_specnames)
                result = (result,
                          lcg.p(_("Related views:")),
                          lcg.ul([self._spec_link(name) for name in related_specnames]))
            return result

        parser = lcg.Parser()
        content = lcg.Container(
            [lcg.TableOfContents(title=_("Contents"))] + [
                lcg.Section(title=title, content=func(content)) for title, func, content in (
                    (_("Overview"), lcg.p,
                     self._description('description', spec_name, None, view_spec.description())),
                    (_("Description"), parser.parse,
                     self._description('help', spec_name, None, view_spec.help())),
                    (_("Form fields"), lcg.dl,
                     sorted([(field_label(f), field_description(f)) for f in view_spec.fields()],
                            key=lambda x: x[0])),
                    (_("Profiles"), lcg.dl,
                     [(p.title(), self._description('profile', spec_name, p.id(), p.descr()))
                      for p in view_spec.profiles().unnest()]),
                    (_("Context menu actions"), lcg.dl,
                     [(a.title(), (self._description('action', spec_name, a.id(), a.descr()),
                                   (' ', _("Access Rights"), ': ', ', '.join(a.access_groups()))
                                   if a.access_groups() else ''))
                      for a in view_spec.actions(unnest=True)]),
                    (_("Side forms"), lcg.dl,
                     [(self._spec_link(b.name(), b.title()),
                       self._description('binding', spec_name, b.id(), b.descr()))
                      for b in view_spec.bindings() if b.name()]),
                    (_("Access Rights"), lcg.dl,
                     self._access_rights(spec_name, view_spec)),
                ) if content
            ],
            resources=self._spec_help_resources(spec_name)
        )
        return view_spec.title(), content
Exemplo n.º 4
0
 def help(cls):
     sections = [lcg.Section(title=title, id=section_id, content=lcg.coerce(content))
                 for title, section_id, content in
                 ((_("Instructions"), 'intro', cls._EXERCISE_CLASS.help_intro()),
                  (_("Shortcut Keys"), 'keys', cls._help_keys()),
                  (_("Indicators"), 'indicators', cls._help_indicators()),
                  (_("Control Panel"), 'panel', cls._help_panel()))
                 if content is not None]
     return lcg.Container(sections)
Exemplo n.º 5
0
    def _content(self, lang):
        import wiking
        import wiking.cms

        def descr(option):
            content = [lcg.em(option.description())]
            doc = option.documentation()
            if doc:
                content.append(lcg.p(doc))
            content.append(lcg.p("*Default value:*", formatted=True))
            content.append(lcg.PreformattedText(option.default_string()))
            return content

        import lcg
        # Initial text is taken from configuration module docstring.
        intro = lcg.Parser().parse(lcg.unindent_docstring(wiking.cfg.__doc__))
        # Construct sections according to module and subsections with the config options
        sections = [
            lcg.Section(title=title,
                        content=[
                            lcg.Section(title="Option '%s'" % o.name(),
                                        id=o.name(),
                                        descr=o.description(),
                                        content=descr(o))
                            for o in cfg.options(sort=True) if o.visible()
                        ])
            for title, cfg in (("Wiking Configuration Options", wiking.cfg),
                               ("Wiking CMS Configuration Options",
                                wiking.cms.cfg))
        ]
        overview = [
            lcg.Section(title=section.title() + " Overview",
                        content=lcg.ul(
                            lcg.coerce((lcg.link(s, s.id()), ": ", s.descr()))
                            for s in section.sections()))
            for section in sections
        ]
        return dict(content=intro + overview + sections)
Exemplo n.º 6
0
 def _content(self, lang):
     from wiking import Application
     parser = lcg.Parser()
     # modules = [(k, v) for k, v in wiking.application.__dict__.items()
     #            if type(v) == type(Module) and issubclass(v, Module) \
     #            and v.__module__ == 'wiking.application']
     # modules.sort()
     content = parser.parse(Application.__doc__) + \
         [lcg.TableOfContents(title="Application methods:", depth=1)]
     for name, method in sorted(Application.__dict__.items()):
         if name.startswith('_') or name.startswith('action_') \
                 or not isinstance(method, collections.Callable) or not method.__doc__:
             continue
         args, varargs, varkw, defaults = inspect.getargspec(method)
         title = name + inspect.formatargspec(args[1:], varargs, varkw,
                                              defaults)
         doc = self._ARG_REGEX.sub(lambda m: ":" + m.group(1) + ": ",
                                   inspect.getdoc(method))
         content.append(
             lcg.Section(title=title, content=parser.parse(doc), id=name))
     return dict(content=content)
Exemplo n.º 7
0
 def _spec_help_content(self, spec_name):
     from pytis.form import has_access
     if not has_access(spec_name):
         return (_("Access denied"),
                 lcg.p(_("You don't have permissions for specification „%s“.") % spec_name))
     resolver = pytis.util.resolver()
     def spec_link(spec_name, title=None):
         if title is None:
             try:
                 view_spec = resolver.get(spec_name, 'view_spec')
             except pytis.util.ResolverError as e:
                 title = spec_name
             else:
                 title = view_spec.title()
         return lcg.link('help:spec/%s' % spec_name, title)
     descriptions = self._spec_items_descriptions(spec_name)
     def description(kind, identifier, default):
         return descriptions[kind].get(identifier, default or _("Description not available."))
     def field_label(f):
         label = f.column_label()
         if not label:
             label = f.label() or f.id()
         elif f.label() and f.label() != label:
             label += ' ('+ f.label()+')'
         return label
     def field_description(f):
         result = description('field', f.id(), f.descr())
         related_specnames = [name for name in
                              [f.codebook()] + [link.name() for link in f.links()] if name]
         if related_specnames:
             pytis.util.remove_duplicates(related_specnames)
             result = (result,
                       lcg.p(_("Related views:")),
                       lcg.ul([spec_link(name) for name in related_specnames]))
         return result
     try:
         view_spec = resolver.get(spec_name, 'view_spec')
     except pytis.util.ResolverError as e:
         return None, None
     data = pytis.data.dbtable('e_pytis_help_spec', ('spec_name', 'description', 'help'),
                               config.dbconnection)
     row = data.row((pytis.data.Value(data.find_column('spec_name').type(), spec_name),))
     if row:
         spec_description = row['description'].value()
         spec_help = row['help'].value()
     else:
         spec_description = view_spec.description()
         spec_help = view_spec.help()
     parser = lcg.Parser()
     sections = [
         lcg.Section(title=title, content=f(content))
         for title, f, content in (
             (_("Overview"), lcg.p, spec_description),
             (_("Description"), parser.parse, spec_help),
             (_("Form fields"), lcg.dl,
              sorted([(field_label(f), field_description(f)) for f in view_spec.fields()],
                     key=lambda x: x[0])),
             (_("Profiles"), lcg.dl,
              [(p.title(), description('profile', p.id(), p.descr()))
               for p in view_spec.profiles().unnest()]),
             (_("Context menu actions"), lcg.dl,
              [(a.title(), description('action', a.id(), a.descr()))
               for a in view_spec.actions(unnest=True)]),
             (_("Side forms"), lcg.dl,
              [(spec_link(b.name(), b.title()), description('binding', b.id(), b.descr()))
               for b in view_spec.bindings() if b.name()]),
             )
         if content]
     #data_spec = resolver.get(specname, 'data_spec')
     #rights = data_spec.access_rights()
     #if rights:
     #    content += "\n\n== %s ==\n\n" % _(u"Přístupová práva")
     #    for perm in (pd.Permission.VIEW,
     #                 pd.Permission.INSERT,
     #                 pd.Permission.UPDATE,
     #                 pd.Permission.DELETE,
     #                 pd.Permission.EXPORT):
     #        groups = [g for g in rights.permitted_groups(perm, None) if g]
     #        content += ":%s:: %s\n" % (perm, ', '.join(map(str, groups)) or _(u"Nedefinováno"))
     storage = pytis.presentation.DbAttachmentStorage('e_pytis_help_spec_attachments',
                                                      'spec_name', spec_name)
     return view_spec.title(), lcg.Container(sections, resources=storage.resources())