def _lcg(self): contents = self._lcg_contents() if len(contents) > 1: contents = [lcg.Container(contents, orientation=HORIZONTAL)] return lcg.Container(contents, halign=self._ALIGNMENT, orientation=VERTICAL)
def _format(self, context): blocks = self._parser.parse(context.localize(self._value().export())) if len(blocks) == 1 and isinstance(blocks[0], lcg.Paragraph): content = lcg.Container(blocks[0].content()) else: content = lcg.Container(blocks) return context.generator().div(content.export(context))
def action_view(self, req, record): text = record['content'].value() modname = record['modname'].value() globals = self.globals(req) storage = self._attachment_storage(record) if storage: resources = storage.resources() else: resources = () if text: text = lcg.MacroParser(globals=globals).parse(text) parser = lcg.Parser() if self._SEPARATOR.search(text): pre, post = [parser.parse(part) for part in self._SEPARATOR.split(text, maxsplit=2)] else: pre, post = parser.parse(text), [] else: pre, post = [], [] if modname is not None: binding = self._embed_binding(modname) result = req.forward(wiking.module(modname), binding=binding, record=record, title=record['title'].value()) if isinstance(result, wiking.Document): # Embed the resulting document into the current menu item content. content = result.content() if isinstance(content, (tuple, list)): content = list(content) else: content = [content] document = result.clone(title=self._document_title(req, record), subtitle=None, content=lcg.Container(pre + content + post, resources=resources), globals=globals) else: # A wiking.Response instance has been returned by the embedded module. return result elif text is None and record['parent'].value() is None: # Redirect to the first subitem from empty top level items. rows = self._data.get_rows(parent=record['menu_item_id'].value(), published=True, sorting=self._sorting) # TODO: Use only items, which are visible to the current user (access rights). if rows: raise wiking.Redirect('/' + self._menu_item_identifier(rows[0])) else: document = self._document(req, lcg.Container([], resources=resources), record, globals=globals) else: document = self._document(req, lcg.Container(pre + post, resources=resources), record, globals=globals) if modname is None: # Module access is logged in EmbeddablePytisModule._handle(). wiking.module.AccessLog.log(req, None, None) return document
def handle(self, req): req.wmi = False # Will be set to True by `WikingManagementInterface' if needed. preview_mode_param = req.param(self._PREVIEW_MODE_PARAM) if preview_mode_param is not None: req.set_cookie(self._PREVIEW_MODE_COOKIE, preview_mode_param == '1' and '1' or None) wiking.module.CachedTables.reload_info(req) wiking.module.Config.configure(req) modname = self._resolve_modname(req) if modname: return req.forward(wiking.module(modname)) else: try: return super(Application, self).handle(req) except wiking.Forbidden: # The parent method raises Forbidden when there are no menu items to redirect to. if req.check_roles(Roles.CONTENT_ADMIN): # Give the administrator some hints on a fresh install. if wiking.module.Pages.empty(req): return wiking.Document( title=_("Welcome to Wiking CMS"), content=lcg.Container((lcg.p("There are currently no pages."), lcg.p(lcg.link("/?action=insert", _("Create a new page"))))), ) elif not self.preview_mode(req): req.message(_("There are no published pages. " "You need to switch to the Preview mode " "to be able to access the unpublished pages."), req.WARNING) raise
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
def _result_page(self, req, result): if result: content = lcg.Container( [self._result_item(item) for item in result]) else: content = self._empty_result_page() return wiking.Document(self._RESULT_TITLE, content)
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
def _document(self, text): sections, parameters = self._parse_text(text) if len(sections) != 1 or not isinstance(sections[0], lcg.Section): raise Exception("The document has no top-level section:", (self._id, sections,)) s = sections[0] title = s.title() sections = s.content() return title, lcg.Container(sections), parameters
def _content(x): if isinstance(x, dict) and tuple(x.keys()) == (None,): # Handle old hacks gracefully. x = x[None] if isinstance(x, (tuple, list)): x = lcg.Container(x) assert x is None or isinstance(x, lcg.Content), x return x
def _lcg(self): if self._family == self.PROPORTIONAL: family = lcg.FontFamily.PROPORTIONAL elif self._family == self.SANS_SERIF: family = lcg.FontFamily.SANS_SERIF elif self._family == self.FIXED_WIDTH: family = lcg.FontFamily.FIXED_WIDTH return lcg.Container(self._lcg_contents(), presentation=lcg.Presentation(font_family=family))
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)
def body(self): content_1 = lcg.coerce('xxx') content_2 = lcg.VSpace(lcg.UMm(500)) return pytis.output.Document( lcg.Container(( content_1, content_2, content_1, )))
def _lcg(self): parser = lcg.Parser() parameters = {} result = lcg.Container(parser.parse(self._text, parameters)) self._parameters = {} for k, v in parameters.items(): self._parameters[k] = v if 'first_page_header' not in self._parameters and 'page_header' in self._parameters: self._parameters['first_page_header'] = self._parameters['page_header'] return result
def _something_to_lcg(something): if isinstance(something, basestring): result = lcg.TextContent(something) elif isinstance(something, (list, tuple,)): result = lcg.Container([_something_to_lcg(s) for s in something], orientation=lcg.Orientation.HORIZONTAL) elif isinstance(something, lcg.Content): result = something else: result = something.lcg() return result
def _content(self, path, lang): filename = '.'.join((path, lang, 'txt')) f = codecs.open(filename, encoding='utf-8') text = "".join(f.readlines()) f.close() content = lcg.Parser().parse(text) if len(content) == 1 and isinstance(content[0], lcg.Section): title = content[0].title() content = content[0].content() else: title = None return title, lcg.Container(content)
def _lcg(self): presentation = lcg.Presentation() if self.arg_boxed: presentation.boxed = True presentation.box_margin = self.arg_box_margin if self.arg_vertical: orientation = lcg.Orientation.VERTICAL else: orientation = lcg.Orientation.HORIZONTAL return lcg.Container(self._lcg_contents(), orientation=orientation, presentation=presentation, halign=lcg.HorizontalAlignment.LEFT, valign=lcg.VerticalAlignment.TOP)
def make_node(row, children): if row['help_id'].value() == topic: # If this is the currently displayed node, create the content. # Other nodes are only generated for their presence in the # menu. parser = lcg.Parser() if row['page_id'].value(): storage = pytis.presentation.DbAttachmentStorage( 'e_pytis_help_pages_attachments', 'page_id', row['page_id'].value()) content = lcg.Container(parser.parse(row['content'].value()), resources=storage.resources()) else: content = [lcg.TableOfContents(title=_("Contents"))] fullname, spec_name = row['fullname'].value(), row['spec_name'].value() if row['menu_help'].value(): content.extend(parser.parse(row['menu_help'].value())) if fullname and fullname.startswith('handle/'): pass elif fullname and fullname.startswith('proc/'): pass elif spec_name == 'export': pass elif spec_name == 'ui': pass elif spec_name: spec_help_content = self._spec_help_content(spec_name)[1] if spec_help_content: content.append(spec_help_content) else: content = () return lcg.ContentNode('help:'+row['help_id'].value(), title=row['title'].value(), descr=row['description'].value(), foldable=True, content=lcg.Container(content), resource_provider=resource_provider, children=[make_node(r, children) for r in children.get(row['position'].value(), ())])
def _lcg(self): def coalesce(a, b): return a if a is not None else b padding = self.arg_padding if padding is not None: if not isinstance(padding, (tuple, list)): padding = (padding, padding, padding, padding) elif len(padding) == 2: padding = (padding[0], padding[1], padding[0], padding[1]) padding = [ self._dimension(coalesce(x, y)) for x, y in zip((self.arg_padding_top, self.arg_padding_right, self.arg_padding_bottom, self.arg_padding_left), padding) ] presentation = dict( font_color=_color(self.arg_color), background_color=_color(self.arg_background), ) if self.arg_boxed: presentation.update( boxed=True, box_margin=self._dimension(self.arg_box_margin), box_radius=self._dimension(self.arg_box_radius), box_width=self._dimension(self.arg_box_width), box_color=_color(self.arg_box_color), box_mask=self.arg_box_mask, ) contents = self._lcg_contents() orientation = self._orientation() if self.arg_spacing: if orientation == VERTICAL: space = [VSpace(self.arg_spacing).lcg()] else: space = [HSpace(self.arg_spacing).lcg()] contents = reduce(lambda a, b: a + space + [b], contents[1:], contents[0:1]) return lcg.Container(contents, orientation=orientation, width=self._dimension(self.arg_width), height=self._dimension(self.arg_height), padding=padding, presentation=lcg.Presentation(**presentation), halign=self.arg_halign, valign=self.arg_valign)
def _application_help_page_content(self, node, uri): globs = node.globals() command, args = globs['command'], globs['args'] if command in (pytis.form.Application.COMMAND_RUN_FORM, pytis.form.Application.COMMAND_NEW_RECORD): content = self._spec_help_content(args['name'])[1] if not content: if command == pytis.form.Application.COMMAND_RUN_FORM: text = _("Opens the %s on specification", args['form_class'].descr()) else: text = _("Inserts a new record into") content = lcg.p(text, ' ', self._spec_link(args['name']), '.') return content return lcg.Container(( lcg.p(_("Runs the command %s with the following arguments:", command.id())), lcg.fieldset([(k, unistr(v)) for k, v in args.items()]) ))
def _application_help_page_content(self, node, uri): self._data.select(condition=pd.EQ('help_id', pd.sval(uri[5:]))) row = self._data.fetchone() self._data.close() if row: if row['page_id'].value(): storage = pytis.presentation.DbAttachmentStorage( 'e_pytis_help_pages_attachments', 'page_id', row['page_id'].value(), ) return lcg.Container(lcg.Parser().parse(row['content'].value() or ''), resources=storage.resources()) if row['menu_help'].value(): return lcg.Parser().parse(row['menu_help'].value()) else: spec_name = row['spec_name'].value() # TODO: Use the default descriptions from HelpUpdater. if spec_name: content = self._spec_help_content(spec_name)[1] if content: return content return lcg.Content()
def mknode(item): # Caution - make the same uri transformation as above to get same # results in all cases (such as for '/'). item_uri = '/' + item.id().strip('/') if item_uri == uri: # Note, the document title should not override the menu item title. # Only the main page heading is affected, but the ContentNode's # title matches the MenuItem's title. title = document.title() or item.title() if title and document.subtitle(): title = lcg.concat(title, ' :: ', document.subtitle()) heading = lcg.TextContent(title) content = document.content() if isinstance(content, (list, tuple)): content = lcg.Container([c for c in content if c is not None]) variants = document.variants() if variants is None: variants = item.variants() globals_ = document.globals() else: variants = item.variants() heading = None content = None globals_ = None if variants is None: variants = all_variants node = lcg.ContentNode(item_uri, title=item.title(), heading=heading, descr=item.descr(), content=content, variants=[lcg.Variant(v) for v in variants], active=item.active(), foldable=item.foldable(), hidden=item.hidden() or lang not in variants, children=[mknode(i) for i in item.submenu()], resource_provider=resource_provider, globals=globals_) nodes[item_uri] = node return node
def _lcg(self): return lcg.Container( self._lcg_contents(), presentation=lcg.Presentation(font_size=self._size))
# GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. """Default presentation file for Braille output.""" from __future__ import unicode_literals import lcg import os braille_tables = {'en': ['en-us-g1.ctb'], 'en2': ['en-us-g2.ctb'], 'cs': ['cs-g1.ctb', os.path.join(os.path.dirname(lcg.__file__), 'export/braille-tables/lcg.utb')], 'nemeth': ['nemeth.ctb']} braille_hyphenation_tables = {'en': 'hyph_en_US.dic', 'cs': 'hyph_cs_CZ.dic'} page_width = lcg.UFont(20) page_height = lcg.UFont(10) left_page_footer = lcg.Container((lcg.PageNumber(), lcg.HSpace(lcg.UFont(3)), lcg.PageHeading(),)) right_page_footer = lcg.Container((lcg.PageHeading(), lcg.HSpace(lcg.UFont(3)), lcg.PageNumber(),)) braille_math_rules = 'czech' # 'nemeth', 'czech'
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())
def _lcg(self): presentation = lcg.Presentation() presentation.font_size = self._size return lcg.Container(self._lcg_contents(), presentation=presentation)
def _lcg(self): presentation = lcg.Presentation() presentation.bold = presentation.italic = False return lcg.Container(self._lcg_contents(), presentation=presentation)
def _lcg(self): return lcg.Container(self._lcg_contents(), valign=lcg.VerticalAlignment.CENTER, orientation=lcg.Orientation.HORIZONTAL)
def _lcg(self): return lcg.Container(self._lcg_contents(), orientation=lcg.Orientation.HORIZONTAL)
def help_page(self, topic): """Return the help page for given topic as lcg.ContentNode instance.""" resource_dirs = [d[:-3]+'resources' for d in sys.path if d.endswith('/pytis/lib') or d.endswith('/lcg/lib')] resource_provider = lcg.ResourceProvider(dirs=resource_dirs) def make_node(row, children): if row['help_id'].value() == topic: # If this is the currently displayed node, create the content. # Other nodes are only generated for their presence in the # menu. parser = lcg.Parser() if row['page_id'].value(): storage = pytis.presentation.DbAttachmentStorage( 'e_pytis_help_pages_attachments', 'page_id', row['page_id'].value()) content = lcg.Container(parser.parse(row['content'].value()), resources=storage.resources()) else: content = [lcg.TableOfContents(title=_("Contents"))] fullname, spec_name = row['fullname'].value(), row['spec_name'].value() if row['menu_help'].value(): content.extend(parser.parse(row['menu_help'].value())) if fullname and fullname.startswith('handle/'): pass elif fullname and fullname.startswith('proc/'): pass elif spec_name == 'export': pass elif spec_name == 'ui': pass elif spec_name: spec_help_content = self._spec_help_content(spec_name)[1] if spec_help_content: content.append(spec_help_content) else: content = () return lcg.ContentNode('help:'+row['help_id'].value(), title=row['title'].value(), descr=row['description'].value(), foldable=True, content=lcg.Container(content), resource_provider=resource_provider, children=[make_node(r, children) for r in children.get(row['position'].value(), ())]) #data = pytis.data.dbtable('ev_pytis_user_help', # ('help_id', 'fullname', 'spec_name', 'page_id', 'position', # 'title', 'description', 'menu_help', 'content', 'language',), # config.dbconnection) #data.select(condition=pytis.data.EQ('language', pytis.data.sval(current_language())), # sort=(('position', pytis.data.ASCENDENT),)) data = pytis.data.dbtable('ev_pytis_user_help', ('help_id', 'fullname', 'spec_name', 'page_id', 'position', 'title', 'description', 'menu_help', 'content',), config.dbconnection) data.select(sort=(('position', pytis.data.ASCENDENT),)) children = {} while True: row = data.fetchone() if not row: break parent = '.'.join(row['position'].value().split('.')[:-1]) children.setdefault(parent, []).append(row) data.close() nodes = [lcg.ContentNode('help:application', title=_("%s application help") % config.application_name, content=lcg.NodeIndex(), resource_provider=resource_provider, children=[make_node(r, children) for r in children['']]), self._pytis_help(resource_dirs), lcg.ContentNode('NotFound', title=_("Not Found"), hidden=True, content=lcg.p(_("The requested help page not found: %s", topic)), resource_provider=resource_provider)] if topic.startswith('spec/'): # Separate specification descriptions are not in the menu generated # from ev_pytis_help. If specification description page is # requested, we generate one and add it to the menu here. spec_name = topic[5:] title, content = self._spec_help_content(spec_name) if title and content: content = lcg.Container((lcg.TableOfContents(title=_("Contents")), content)) node = lcg.ContentNode('help:'+topic, title=title, hidden=True, content=content, resource_provider=resource_provider) nodes.append(node) root = lcg.ContentNode('help:', content=lcg.Content(), hidden=True, children=nodes) return root.find_node('help:'+topic) or root.find_node('NotFound')
def _search_form(self, req, message=None): content = [] if message is not None: content.append(lcg.p(message)) content = [self.SearchForm(req)] return wiking.Document(self._SEARCH_TITLE, lcg.Container(content))