class Report(EmptyTable): """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. """ detail_layout = "body" do_print = DirectPrintAction() report_items = None @classmethod def request(self, **kw): """Return an action request on this actor. """ kw.update(actor=self) return ReportRequest(**kw) @classmethod 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(unicode(A.label)) if A.help_text: yield E.p(unicode(A.help_text)) yield A @fields.virtualfield(fields.HtmlBox()) def body(cls, self, ar): return ar.story2html(self.get_story(ar)) # elems = tuple(ar.story2html(self.get_story(ar))) # self.get_story(ar), master_instance=self)) # if None in elems: # return "20150703 {0}".format(elems) # return E.div(*elems) @classmethod 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
class Story(model.Model): class Meta: abstract = True def get_story(self, ar): return [] @fields.virtualfield(fields.HtmlBox()) def body(self, ar): if ar is None: return '' # ar.master_instance = self html = ar.renderer.show_story( ar, self.get_story(ar), header_level=1) return ar.html_text(html) # return ar.html_text(ar.story2html( # self.get_story(ar), header_level=1)) def as_appy_pod_xml(self, apr): chunks = tuple(apr.story2odt( self.get_story(apr.ar), master_instance=self)) return str('').join(chunks) # must be utf8 encoded
class Report(EmptyTable): """ A special kind of :class:`EmptyTable` used to create complex "reports". A report is a series of headings, paragraphs and tables combined into a single printable and previewable document. When subclassing this, application code must either define :attr:`report_items` or implement an alternative :meth:`get_story`. :class:`lino_xl.lib.courses.StatusReport` :class:`lino_xl.lib.ledger.Situation` :class:`lino_xl.lib.ledger.ActivityReport` """ detail_layout = "body" do_print = DirectPrintAction() # go_button = ExplicitRefresh() report_items = None """ """ # @classmethod # def request(self, **kw): # """Return an action request on this actor. # """ # kw.update(actor=self) # return ActionRequest(**kw) @classmethod def get_template_groups(self): return ['report', self.app_label + '/' + self.__name__] # @classmethod # def get_print_templates(self, bm, action): # """Called from EmptyTableRow. # Overrides # :meth:`lino.modlib.printing.mixins.Printable.get_print_templates` # """ # if isinstance(bm, SimpleBuildMethod): # return ['Report'+bm.template_ext] # return [bm.get_default_template(self)] # return ['Report'+bm.template_ext, bm.get_default_template(self)] @classmethod def get_build_options(self, bm, **opts): if bm.templates_name == 'wk': opts['footer-left'] = "<p>Footer [page]</p>" return opts # @classmethod # def get_title_base(self, ar): # return self.title or self.label @classmethod def get_title(self, ar): return self.title or self.label @classmethod def get_story(cls, self, ar): """ Yield a sequence of story items. Every item can be (1) an ElementTree element or (2) a table or (3) an action request. """ # cls.check_params(cls.param_values) 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 @fields.virtualfield(fields.HtmlBox()) def body(cls, self, ar): ar.master_instance = self return ar.story2html(self.get_story(ar)) @classmethod 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 @classmethod def to_rst(self, ar, column_names=None, **kwargs): raise Exception("To be replaced by rt.show()")