def __init__(self, context, agenda_item, filename, title): self.agenda_item = agenda_item self.excerpt_protocol_data = ExcerptProtocolData( self.agenda_item.meeting, [self.agenda_item]) self.filename = filename super(MergeDocxExcerptCommand, self).__init__(context=context, filename=filename, data=None, title=title)
def test_excerpt_json_does_not_contain_start_page(self): with freeze(datetime(2018, 5, 4)): data = ExcerptProtocolData(self.meeting).get_processed_data() self.assertEqual( { 'agenda_items': [], 'protocol': { 'type': u'Protocol-Excerpt' }, 'document': { 'generated': u'04.05.2018' }, 'participants': { 'other': [], 'members': [] }, 'committee': { 'name': u'Gemeinderat' }, 'mandant': { 'name': u'Client1' }, 'meeting': { 'date': u'13.12.2011', 'start_time': u'09:30 AM', 'end_time': u'11:45 AM', 'number': 11, 'location': u'B\xe4rn', } }, data)
def test_excerpt_json_does_not_contain_start_page(self): data = ExcerptProtocolData(self.meeting).data self.assertEqual( { 'agenda_items': [], 'protocol': { 'type': u'Protocol-Excerpt' }, 'participants': { 'other': [], 'members': [] }, 'committee': { 'name': u'Gemeinderat' }, 'mandant': { 'name': u'Client1' }, 'meeting': { 'date': u'Dec 13, 2011', 'start_time': u'09:30 AM', 'end_time': u'11:45 AM', 'number': 11, 'location': u'B\xe4rn', } }, data)
def debug_excerpt_docxcompose(self): if not self.is_manager(): raise Forbidden if self.agenda_item.is_paragraph: raise NotFound excerpt_protocol_data = ExcerptProtocolData( self.meeting, [self.agenda_item]) header_template = self.agenda_item.get_excerpt_header_template() suffix_template = self.agenda_item.get_excerpt_suffix_template() with ZipGenerator() as generator: if header_template: sablon = Sablon(header_template).process( excerpt_protocol_data.as_json()) generator.add_file( u'000_excerpt_header_template.docx', StringIO(sablon.file_data)) document = self.agenda_item.resolve_document() filename = u'001_agenda_item_{}.docx'.format( safe_unicode(document.Title())) generator.add_file(filename, document.file.open()) if suffix_template: sablon = Sablon(suffix_template).process( excerpt_protocol_data.as_json()) generator.add_file( u'002_excerpt_suffix_template.docx', StringIO(sablon.file_data)) # Return zip response = self.request.response zip_file = generator.generate() filename = '{}.zip'.format(normalize_path(self.meeting.title)) response.setHeader( "Content-Disposition", 'inline; filename="{0}"'.format( safe_unicode(filename).encode('utf-8'))) response.setHeader("Content-type", "application/zip") response.setHeader( "Content-Length", os.stat(zip_file.name).st_size) return filestream_iterator(zip_file.name, 'rb')
def debug_excerpt_docxcompose(self): if not api.user.has_permission('cmf.ManagePortal'): raise Forbidden if self.agenda_item.is_paragraph: raise NotFound excerpt_protocol_data = ExcerptProtocolData( self.meeting, [self.agenda_item]) header_template = self.agenda_item.get_excerpt_header_template() suffix_template = self.agenda_item.get_excerpt_suffix_template() with ZipGenerator() as generator: if header_template: sablon = Sablon(header_template).process( excerpt_protocol_data.as_json()) generator.add_file( u'000_excerpt_header_template.docx', StringIO(sablon.file_data)) document = self.agenda_item.resolve_document() filename = u'001_agenda_item_{}.docx'.format( safe_unicode(document.Title())) generator.add_file(filename, document.file.open()) if suffix_template: sablon = Sablon(suffix_template).process( excerpt_protocol_data.as_json()) generator.add_file( u'002_excerpt_suffix_template.docx', StringIO(sablon.file_data)) # Return zip response = self.request.response zip_file = generator.generate() filename = '{}.zip'.format(normalize_path(self.meeting.title)) response.setHeader( "Content-Disposition", 'inline; filename="{0}"'.format( safe_unicode(filename).encode('utf-8'))) response.setHeader("Content-type", "application/zip") response.setHeader( "Content-Length", os.stat(zip_file.name).st_size) return filestream_iterator(zip_file.name, 'rb')
class MergeDocxExcerptCommand(CreateDocumentCommand): """Create or update a merged excerpt word file. If an excerpt header is available it is considered the master document. If not, the agenda item`s file is considered the master document. """ def __init__(self, context, agenda_item, filename, title): self.agenda_item = agenda_item self.excerpt_protocol_data = ExcerptProtocolData( self.agenda_item.meeting, [self.agenda_item]) self.filename = filename super(MergeDocxExcerptCommand, self).__init__( context=context, filename=filename, data=None, title=title) def generate_file_data(self): header_template = self.agenda_item.get_excerpt_header_template() suffix_template = self.agenda_item.get_excerpt_suffix_template() agenda_item_document = self.agenda_item.resolve_document() has_header_template = header_template is not None if has_header_template and suffix_template is None: return agenda_item_document.file.data if has_header_template: sablon = self.get_sablon(template=header_template) master_data = sablon.file_data else: master_data = agenda_item_document.file.data with DocxMergeTool(master_data, remove_property_fields=False) as merge_tool: if has_header_template: merge_tool.add(agenda_item_document.file.data) if suffix_template is not None: sablon = self.get_sablon(template=suffix_template) merge_tool.add(sablon.file_data) return merge_tool() def get_sablon(self, template): return Sablon(template).process(self.excerpt_protocol_data.as_json()) def execute(self): self.set_file( self.filename, self.generate_file_data(), MIME_DOCX, ) return super(MergeDocxExcerptCommand, self).execute()
def __init__(self, context, agenda_item, filename, title): self.agenda_item = agenda_item self.excerpt_protocol_data = ExcerptProtocolData( self.agenda_item.meeting, [self.agenda_item]) self.filename = filename super(MergeDocxExcerptCommand, self).__init__( context=context, filename=filename, data=None, title=title)
def get_meeting_data(self, meeting): return ExcerptProtocolData( meeting, self.agenda_items, include_initial_position=self.include_initial_position, include_legal_basis=self.include_legal_basis, include_considerations=self.include_considerations, include_proposed_action=self.include_proposed_action, include_discussion=self.include_discussion, include_decision=self.include_decision, include_publish_in=self.include_publish_in, include_disclose_to=self.include_disclose_to, include_copy_for_attention=self.include_copy_for_attention)
def get_meeting_data(self, meeting): return ExcerptProtocolData(meeting, [self.agenda_item])