Coverage for lino/utils/report.py : 48%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
# Copyright 2009-2015 Luc Saffre # License: BSD (see file COPYING for details)
.. autosummary::
"""
""" Base class for virtual rows of an :class:`EmptyTable`. An EmptyTableRow instance """
self._table = table VirtualRow.__init__(self, **kw)
return str(self._table.label)
# same as Model.get_print_language return settings.SITE.DEFAULT_LANGUAGE.django_code
# same as Model.get_printable_context kw = ar.get_printable_context(**kw) kw.update(this=self) # preferred in new templates kw.update(language=self.get_print_language()) return kw
return [self._table.app_label + '/' + self._table.__name__]
return self._table.app_label + '.' + self._table.__name__
""" Since there is only one EmptyTableRow class, we simulate a getter here by manually creating an InstanceAction. """ v = getattr(self._table, name) if isinstance(v, actions.Action): return actions.InstanceAction(v, self._table, self, None) # 20130525 dd.Report calls `get_story` on `self`, not on the `cls` if callable(v): return curry(v, self) #~ return v #~ raise Exception("") raise AttributeError( "EmptyTableRow on %s has no action and no callable '%s'" % ( self._table, name))
""" A "Table" that has exactly one virtual row and thus is visible only using a Detail view on that row. """
#~ debug_permissions = True #~ has_navigator = False #~ hide_top_toolbar = True
def get_default_action(cls):
def create_instance(self, ar, **kw): if self.parameters: kw.update(ar.param_values)
obj = EmptyTableRow(self, **kw) kw = ar.ah.store.row2dict(ar, obj) obj._data = kw obj.update(**kw) return obj
def get_data_elem(self, name): de = super(EmptyTable, self).get_data_elem(name) if de is not None: return de a = name.split('.') if len(a) == 2: return getattr(getattr(settings.SITE.modules, a[0]), a[1])
# self = ar.selected_rows[0] self = None # ar.actor.create_instance(ar) story = ar.actor.get_story(self, ar) ar.renderer.show_story(story)
# return '\n'.join(ar.story2rst( # ar.actor.get_story(self, ar), **kwargs))
"""A special kind of :class:`EmptyTable` used to create complex "reports". A report is a series of tables combined into a single printable and previewable document.
"""
def request(self, **kw): """Return an action request on this actor.
""" kw.update(actor=self) return ReportRequest(**kw)
def get_story(cls, self, ar): """Yield a sequence of story items. These can be (1) ElementTree elements or (2) AbstractTable or (3) action requests.
""" if cls.report_items is None: raise Exception("{0} has no report_items".format(cls)) for A in cls.report_items: yield E.h2(str(A.label)) if A.help_text: yield E.p(str(A.help_text)) yield A
def body(cls, self, ar): return ar.story2html(self.get_story(ar))
def as_appy_pod_xml(cls, self, apr): chunks = tuple(apr.story2odt( self.get_story(apr.ar), master_instance=self)) return str('').join(chunks) # must be utf8 encoded
|