def _render_document(self, pod_template, output_format, sub_documents, raiseOnError=False, **kwargs): """ Render a single document of type 'output_format' using the odt file 'document_template' as the generation template. Subdocuments is a dictionnary of previously generated subtemplate that will be merged into the current generated document. """ document_template = pod_template.get_file() temp_filename = tempfile.mktemp('.{extension}'.format(extension=output_format)) # Prepare rendering context helper_view = self.get_generation_context_helper() generation_context = self._get_generation_context(helper_view, pod_template=pod_template) # enrich the generation context with previously generated documents utils.update_dict_with_validation(generation_context, sub_documents, _("Error when merging merge_templates in generation context")) # enable optimalColumnWidths if enabled in the config and/or on ConfigurablePodTemplate stylesMapping = {} optimalColumnWidths = False template_optimize_tables = pod_template.get_optimize_tables() if (template_optimize_tables == -1 and config.get_optimize_tables()) or \ template_optimize_tables == 1: stylesMapping = {'table': TableProperties(optimalColumnWidths=True)} optimalColumnWidths = "OCW_.*" # if raiseOnError is not enabled, enabled it in the config excepted if user is a Manager # and currently generated document use odt format if not raiseOnError: if config.get_raiseOnError_for_non_managers(): raiseOnError = True if 'Manager' in api.user.get_roles() and output_format == 'odt': raiseOnError = False renderer = Renderer( StringIO(document_template.data), generation_context, temp_filename, pythonWithUnoPath=config.get_uno_path(), ooPort=config.get_oo_port(), raiseOnError=raiseOnError, imageResolver=api.portal.get(), forceOoCall=True, optimalColumnWidths=optimalColumnWidths, stylesMapping=stylesMapping, **kwargs ) # it is only now that we can initialize helper view's appy pod renderer all_helper_views = self.get_views_for_appy_renderer(generation_context, helper_view) for view in all_helper_views: view._set_appy_renderer(renderer) renderer.run() # return also generation_context to test ist content in tests return temp_filename, generation_context
def _get_generation_context(self, helper_view, pod_template): """ """ gen_context = super(MailingLoopPersistentDocumentGenerationView, self).\ _get_generation_context(helper_view, pod_template) # add mailing list in generation context dic = {'mailing_list': helper_view.mailing_list(), 'mailed_doc': self.document} utils.update_dict_with_validation(gen_context, dic, _("Error when merging mailing_list in generation context")) return gen_context
def mailing_related_generation_context(self, helper_view, gen_context): """ Add mailing related information in generation context """ # We add mailed_data if we have only one element in mailing list mailing_list = helper_view.mailing_list(gen_context) if len(mailing_list) == 0: utils.update_dict_with_validation(gen_context, {'mailed_data': None}, _("Error when merging mailed_data in generation context")) elif len(mailing_list) == 1: utils.update_dict_with_validation(gen_context, {'mailed_data': mailing_list[0]}, _("Error when merging mailed_data in generation context"))
def _get_generation_context(self, helper_view, pod_template): """ Return the generation context for the current document. """ generation_context = self.get_base_generation_context(helper_view, pod_template) utils.update_dict_with_validation(generation_context, {'context': getattr(helper_view, 'context', None), 'view': helper_view}, _("Error when merging helper_view in generation context")) utils.update_dict_with_validation(generation_context, self._get_context_variables(pod_template), _("Error when merging context_variables in generation context")) return generation_context
def _get_generation_context(self, helper_view, pod_template): """ """ gen_context = super(MailingLoopPersistentDocumentGenerationView, self). \ _get_generation_context(helper_view, pod_template) # add variable context from original template utils.update_dict_with_validation(gen_context, self._get_context_variables(self.orig_template), _("Error when merging context_variables in generation context")) # add mailing list in generation context dic = {'mailing_list': helper_view.mailing_list(gen_context), 'mailed_doc': self.document} utils.update_dict_with_validation(gen_context, dic, _("Error when merging mailing_list in generation context")) return gen_context
def _update_dict_with_validation_helper(self, original_dict, update_dict): res = copy.deepcopy(original_dict) self.assertIsNone(update_dict_with_validation(res, update_dict)) expected = copy.deepcopy(original_dict) expected.update(update_dict) self.assertDictEqual(res, expected)
def _get_generation_context(self, helper_view, pod_template): """ Return the generation context for the current document. This method is common for OMPDGenerationView and OMMLPDGenerationView """ generation_context = super(OMPDGenerationView, self)._get_generation_context(helper_view, pod_template) if base_hasattr(self, 'document'): # Mailing ! We use the same scan_id scan_id = self.document.scan_id elif helper_view.real_context.id == 'test_creation_modele': client_id = base.get_config('client_id') scan_id = '%s2%s00000000' % (client_id[0:2], client_id[2:6]) else: scan_id = next_scan_id(file_portal_types=['dmsommainfile'], scan_type='2') scan_id = 'IMIO{0}'.format(scan_id) update_dict_with_validation(generation_context, {'scan_id': scan_id, 'barcode': generate_barcode(scan_id).read()}, _dg("Error when merging 'scan_id' in generation context")) return generation_context
def _get_generation_context(self, helper_view, pod_template): """ Return the generation context for the current document. """ generation_context = self.get_base_generation_context() utils.update_dict_with_validation(generation_context, {'context': getattr(helper_view, 'context', None), 'view': helper_view}, _("Error when merging helper_view in generation context")) utils.update_dict_with_validation(generation_context, self._get_context_variables(pod_template), _("Error when merging context_variables in generation context")) # We add mailed_data if we have only one element in mailing list mailing_list = helper_view.mailing_list() if len(mailing_list) == 1: utils.update_dict_with_validation(generation_context, {'mailed_data': mailing_list[0]}, _("Error when merging mailed_data in generation context")) return generation_context
def _render_document(self, pod_template, output_format, sub_documents, raiseOnError=False, **kwargs): """ Render a single document of type 'output_format' using the odt file 'document_template' as the generation template. Subdocuments is a dictionnary of previously generated subtemplate that will be merged into the current generated document. """ document_template = pod_template.get_file() tmp_dir = os.getenv('CUSTOM_TMP', None) temp_filename = tempfile.mktemp( suffix='.{extension}'.format(extension=output_format), dir=tmp_dir) # Prepare rendering context helper_view = self.get_generation_context_helper() generation_context = self._get_generation_context( helper_view, pod_template=pod_template) # enrich the generation context with previously generated documents utils.update_dict_with_validation( generation_context, sub_documents, _("Error when merging merge_templates in generation context")) # enable optimalColumnWidths if enabled in the config and/or on ConfigurablePodTemplate stylesMapping = {} optimalColumnWidths = "OCW_.*" distributeColumns = "DC_.*" column_modifier = pod_template.get_column_modifier() if column_modifier == -1: column_modifier = config.get_column_modifier() if column_modifier == 'disabled': optimalColumnWidths = False distributeColumns = False else: stylesMapping = { 'table': TableProperties(columnModifier=column_modifier != 'nothing' and column_modifier or None) } # if raiseOnError is not enabled, enabled it in the config excepted if user is a Manager # and currently generated document use odt format if not raiseOnError: if config.get_raiseOnError_for_non_managers(): raiseOnError = True if 'Manager' in api.user.get_roles( ) and output_format == 'odt': raiseOnError = False # stylesMapping.update({'para[class=None, parent != cell]': 'texte_delibe', # 'para[class=xSmallText, parent != cell]': 'bodyXSmall', # 'para[class=smallText, parent != cell]': 'bodySmall', # 'para[class=largeText, parent != cell]': 'bodyLarge', # 'para[class=xLargeText, parent != cell]': 'bodyXLarge', # 'para[class=indentation, parent != cell]': 'bodyIndentation', # 'para[class=None, parent = cell]': 'cell_delibe', # 'table': TableProperties(cellContentStyle='cell_delibe'), # 'para[class=xSmallText, parent = cell]': 'cellXSmall', # 'para[class=smallText, parent = cell]': 'cellSmall', # 'para[class=largeText, parent = cell]': 'cellLarge', # 'para[class=xLargeText, parent = cell]': 'cellXLarge', # 'para[class=indentation, parent = cell]': 'cellIndentation', # }) # stylesMapping.update({'para[class=None,parent!=cell]': 'texte_delibe', # 'para[class=xSmallText,parent!=cell]': 'bodyXSmall', # 'para[class=smallText,parent!=cell]': 'bodySmall', # 'para[class=largeText,parent!=cell]': 'bodyLarge', # 'para[class=xLargeText,parent!=cell]': 'bodyXLarge', # 'para[class=indentation,parent!=cell]': 'bodyIndentation', # 'para[class=xSmallText,parent=cell]': 'cellXSmall', # 'para[class=smallText,parent=cell]': 'cellSmall', # 'para[class=largeText,parent=cell]': 'cellLarge', # 'para[class=xLargeText,parent=cell]': 'cellXLarge', # 'para[class=indentation,parent=cell]': 'cellIndentation', # }) renderer = Renderer(StringIO(document_template.data), generation_context, temp_filename, pythonWithUnoPath=config.get_uno_path(), ooServer=config.get_oo_server(), ooPort=config.get_oo_port(), raiseOnError=raiseOnError, imageResolver=api.portal.get(), forceOoCall=True, optimalColumnWidths=optimalColumnWidths, distributeColumns=distributeColumns, stylesMapping=stylesMapping, stream=config.get_use_stream(), **kwargs) # it is only now that we can initialize helper view's appy pod renderer all_helper_views = self.get_views_for_appy_renderer( generation_context, helper_view) for view in all_helper_views: view._set_appy_renderer(renderer) renderer.run() # return also generation_context to test ist content in tests return temp_filename, generation_context
def _render_document(self, pod_template, output_format, sub_documents, raiseOnError=False, **kwargs): """ Render a single document of type 'output_format' using the odt file 'document_template' as the generation template. Subdocuments is a dictionnary of previously generated subtemplate that will be merged into the current generated document. """ document_template = pod_template.get_file() temp_filename = tempfile.mktemp('.{extension}'.format(extension=output_format)) # Prepare rendering context helper_view = self.get_generation_context_helper() generation_context = self._get_generation_context(helper_view, pod_template=pod_template) # enrich the generation context with previously generated documents utils.update_dict_with_validation(generation_context, sub_documents, _("Error when merging merge_templates in generation context")) # enable optimalColumnWidths if enabled in the config and/or on ConfigurablePodTemplate stylesMapping = {} optimalColumnWidths = "OCW_.*" distributeColumns = "DC_.*" column_modifier = pod_template.get_column_modifier() if column_modifier == -1: column_modifier = config.get_column_modifier() if column_modifier == 'disabled': optimalColumnWidths = False distributeColumns = False else: stylesMapping = { 'table': TableProperties(columnModifier=column_modifier != 'nothing' and column_modifier or None)} # if raiseOnError is not enabled, enabled it in the config excepted if user is a Manager # and currently generated document use odt format if not raiseOnError: if config.get_raiseOnError_for_non_managers(): raiseOnError = True if 'Manager' in api.user.get_roles() and output_format == 'odt': raiseOnError = False renderer = Renderer( StringIO(document_template.data), generation_context, temp_filename, pythonWithUnoPath=config.get_uno_path(), ooPort=config.get_oo_port(), raiseOnError=raiseOnError, imageResolver=api.portal.get(), forceOoCall=True, optimalColumnWidths=optimalColumnWidths, distributeColumns=distributeColumns, stylesMapping=stylesMapping, **kwargs ) # it is only now that we can initialize helper view's appy pod renderer all_helper_views = self.get_views_for_appy_renderer(generation_context, helper_view) for view in all_helper_views: view._set_appy_renderer(renderer) renderer.run() # return also generation_context to test ist content in tests return temp_filename, generation_context