def _make_table(self): form = self._form if form is None: return lcg.Content() table = pytis.output.data_table(form.view_spec(), form.data(), condition=form.condition(), sorting=form.sorting(), transaction=self._transaction) return table.lcg()
def __init__(self, resolver, output_resolvers, template_id, form=None, form_bindings=None, parameters={}, language=None, translations=(), spec_kwargs=None): """Arguments: resolver -- form specification resolver output_resolvers -- resolver of template names and data objects; may also be a non-empty sequence of resolvers, in such a case the first resolver not throwing 'ResolverError' when accessing the template will be used template_id -- id of the output template, string form -- current form; 'Form' instance or 'None' form_bindings -- bindings of the current form (if it is the main form of a dual form) as a sequence of 'Binding' instances; or 'None' parameters -- dictionary of form parameters language -- language code to pass to the exporter context translations -- translations to pass to PDFExporter spec_kwargs -- dictionary of keyword arguments to pass to the print specification constructor """ self._resolver = resolver self._output_resolvers = xtuple(output_resolvers) self._template_id = template_id self._parameters = HashableDict(parameters) self._language = language self._translations = translations self._spec_kwargs = spec_kwargs or {} if not self._resolve(template_id, 'init'): raise AbortOutput() self._doc_header, __ = self._resolve(template_id, 'doc_header') self._doc_footer, __ = self._resolve(template_id, 'doc_footer') self._page_header, __ = self._resolve(template_id, 'page_header', default=None) self._first_page_header, __ = self._resolve(template_id, 'first_page_header', default=self._page_header) page_number = pytis.output.Center('Strana ', pytis.output.PageNumber()) self._page_footer, __ = self._resolve(template_id, 'page_footer', default=page_number) self._page_background, __ = self._resolve(template_id, 'background', default=None) self._page_layout, __ = self._resolve(template_id, 'page_layout', default={}) style, __ = self._resolve(template_id, 'style', default=None) if style: style_parser = lcg.StyleFile() style_parser.read(StringIO.StringIO(style)) # doesn't work with cStringIO self._style = style_parser.presentations() else: self._style = None body, __ = self._resolve(template_id, 'body') if body is None: # In order to apply style parameters correctly temp_body = pytis.output.StructuredText('') else: temp_body = body parameters = copy.copy(self._template_parameters(temp_body)) for p, a in (('page_header', self._page_header,), ('page_footer', self._page_footer,), ('first_page_header', self._first_page_header,), ('page_background', self._page_background,), ): if p not in parameters: if a is None: value = None elif isinstance(a, list): # presentation style value = a elif isinstance(a, lcg.Content): value = a else: value = a.lcg() parameters[p] = value self._body_parameters = parameters if ((not isinstance(body, pytis.output.Document) and body and not (isinstance(body, (tuple, list,)) and body and isinstance(body[0], pytis.output.Document)))): body.lcg() # to generate parameters body = pytis.output.Document(body, **parameters) else: # It's unclear how to interpret this situation. In the Lout # formatter the parameters were apparently taken from # specifications and applied globally, but they could also be given # in the Document's (and ignored there?), with the exception of # background. So let's them add to Document's if they are not # present there yet. if isinstance(body, pytis.output.Document): body_list = [body] else: body_list = body if isinstance(body_list, (tuple, list,)): for document in body_list: for k, v in parameters.items(): name = 'arg_' + k if getattr(document, name) is None: setattr(document, name, v) self._body = body self._form = form self._form_bindings = form_bindings self._row_template, __ = self._resolve(template_id, 'row', default=None) self._application_variables, __ = self._resolve(template_id, 'variables', default={}) if form is None: self._codebooks = None else: self._codebooks = self._retrieve_codebooks(form.view_spec(), resolver=self._resolver)
def __init__(self, resolver, output_resolvers, template_id, form=None, form_bindings=None, parameters={}, language=None, translations=()): """Arguments: resolver -- form specification resolver output_resolvers -- resolver of template names and data objects; may also be a non-empty sequence of resolvers, in such a case the first resolver not throwing 'ResolverError' when accessing the template will be used template_id -- id of the output template, string form -- current form; 'Form' instance or 'None' form_bindings -- bindings of the current form (if it is the main form of a dual form) as a sequence of 'Binding' instances; or 'None' parameters -- dictionary of form parameters language -- language code to pass to the exporter context translations -- translations to pass to PDFExporter """ self._resolver = resolver self._output_resolvers = xtuple(output_resolvers) self._template_id = template_id self._parameters = HashableDict(parameters) self._language = language self._translations = translations if not self._resolve(template_id, 'init'): raise AbortOutput() self._doc_header, __ = self._resolve(template_id, 'doc_header') self._doc_footer, __ = self._resolve(template_id, 'doc_footer') self._page_header, __ = self._resolve(template_id, 'page_header', default=None) self._first_page_header, __ = self._resolve(template_id, 'first_page_header', default=self._page_header) page_number = pytis.output.Center('Strana ', pytis.output.PageNumber()) self._page_footer, __ = self._resolve(template_id, 'page_footer', default=page_number) self._page_background, __ = self._resolve(template_id, 'background', default=None) self._page_layout, __ = self._resolve(template_id, 'page_layout', default={}) style, __ = self._resolve(template_id, 'style', default=None) if style: style_parser = lcg.StyleFile() style_parser.read(StringIO.StringIO(style)) # doesn't work with cStringIO self._style = style_parser.presentations() else: self._style = None body, __ = self._resolve(template_id, 'body') if body is None: # In order to apply style parameters correctly temp_body = pytis.output.StructuredText('') else: temp_body = body parameters = copy.copy(self._template_parameters(temp_body)) for p, a in (('page_header', self._page_header,), ('page_footer', self._page_footer,), ('first_page_header', self._first_page_header,), ('page_background', self._page_background,), ): if p not in parameters: if a is None: value = None elif isinstance(a, list): # presentation style value = a elif isinstance(a, lcg.Content): value = a else: value = a.lcg() parameters[p] = value self._body_parameters = parameters if ((not isinstance(body, pytis.output.Document) and body and not (isinstance(body, (tuple, list,)) and body and isinstance(body[0], pytis.output.Document)))): body.lcg() # to generate parameters body = pytis.output.Document(body, **parameters) else: # It's unclear how to interpret this situation. In the Lout # formatter the parameters were apparently taken from # specifications and applied globally, but they could also be given # in the Document's (and ignored there?), with the exception of # background. So let's them add to Document's if they are not # present there yet. if isinstance(body, pytis.output.Document): body_list = [body] else: body_list = body if isinstance(body_list, (tuple, list,)): for document in body_list: for k, v in parameters.items(): name = 'arg_' + k if getattr(document, name) is None: setattr(document, name, v) self._body = body self._form = form self._form_bindings = form_bindings self._row_template, __ = self._resolve(template_id, 'row', default=None) self._application_variables, __ = self._resolve(template_id, 'variables', default={}) if form is None: self._codebooks = None else: self._codebooks = self._retrieve_codebooks(form.view_spec(), resolver=self._resolver)