def getPDFForm(self): """ Returns an PDF Form instance (stored in RAM) """ if self.getDefaultScribusFormValue() is None: return portal_type_name = self.getId().replace(' ', '') pdf_form_name = '%s_view%sAsPdf' % (portal_type_name, portal_type_name) pdf_file = StringIO.StringIO(self.getDefaultPdfFormValue().getData()) pdf_form = PDFForm(pdf_form_name, portal_type_name, pdf_file) pdf_form.manage_upload(pdf_file) import_scribus_file = StringIO.StringIO( self.getDefaultScribusFormValue().getData()) scribus_parser = ScribusParser(import_scribus_file) erp5_properties = scribus_parser.getERP5PropertyDict() def_usePropertySheet = 0 my_prefix = 'my_' prefix_len = len(my_prefix) pages = range(len(erp5_properties)) for page in pages: page_content = erp5_properties[page] for cell_name, field_dict in page_content: # current object is PDF Form if cell_name[:prefix_len] == my_prefix: cell_process_name_list = [] suffix = cell_name[prefix_len:].split('_')[-1] # If properties field are filled in scribus, get Type form # global_properties. Else, guess Type by suffix id (eg: List, Date,...) list_field_type_list = ( 'ListField', 'MultiListField', 'LinesField', ) date_field_type_list = ('DateTimeField', ) suffix_mapping = { 'List': list_field_type_list, 'Date': date_field_type_list } field_type = field_dict.get( 'erp_type', suffix_mapping.get(suffix, [''])[0]) if def_usePropertySheet: # generating PropertySheet and Document, no need to use them to # get field data if field_type in list_field_type_list: TALES = "python: %s " % ', '.join( "here.get%s()" % convertToUpperCase(cell_name[prefix_len:])) elif field_type in date_field_type_list: attributes_dict = field_dict['attributes'] # assign the property input_order input_order = attributes_dict['input_order'] input_order = input_order.replace('y', 'Y') # make the Tales according to the cases date_pattern = '/'.join( ['%%%s' % s for s in list(input_order)]) if not (attributes_dict['date_only']): date_pattern += ' %H:%M' TALES = "python: here.get%s() is not None and here.get%s().strftime('%s') or ''"\ % (convertToUpperCase(cell_name[prefix_len:]), convertToUpperCase(cell_name[prefix_len:]), date_pattern) else: TALES = "python: here.get%s()" %\ convertToUpperCase(cell_name[prefix_len:]) else: if field_type in list_field_type_list: TALES = "python: %s" % ', '.join( "here.getProperty('%s')" % cell_name[prefix_len:]) elif field_type in date_field_type_list: attributes_dict = field_dict['attributes'] # assign the property input_order input_order = attributes_dict['input_order'] input_order = input_order.replace('y', 'Y') # make the Tales according to the cases date_pattern = '/'.join( ['%%%s' % s for s in list(input_order)]) if not (attributes_dict['date_only']): date_pattern += ' %H:%M' TALES = "python: here.getProperty('%s') is not None and here.getProperty('%s').strftime('%s') or ''"\ % (cell_name[prefix_len:], cell_name[prefix_len:], date_pattern) else: TALES = "python: here.getProperty('%s')" % cell_name[ prefix_len:] pdf_form.setCellTALES(cell_name, TALES) import_scribus_file.close() pdf_file.close() self.REQUEST.RESPONSE.setHeader('Content-Type', 'application/pdf') return pdf_form
def getPDFForm(self): """ Returns an PDF Form instance (stored in RAM) """ if self.getDefaultScribusFormValue() is None: return portal_type_name = self.getId().replace(' ','') pdf_form_name ='%s_view%sAsPdf' % (portal_type_name, portal_type_name) pdf_file = StringIO.StringIO(self.getDefaultPdfFormValue().getData()) pdf_form = PDFForm(pdf_form_name, portal_type_name, pdf_file) pdf_form.manage_upload(pdf_file) import_scribus_file = StringIO.StringIO(self.getDefaultScribusFormValue().getData()) scribus_parser = ScribusParser(import_scribus_file) erp5_properties = scribus_parser.getERP5PropertyDict() def_usePropertySheet = 0 my_prefix = 'my_' prefix_len = len(my_prefix) pages = range(len(erp5_properties)) for page in pages: page_content = erp5_properties[page] for cell_name, field_dict in page_content: # current object is PDF Form if cell_name[:prefix_len] == my_prefix: cell_process_name_list = [] suffix = cell_name[prefix_len:].split('_')[-1] # If properties field are filled in scribus, get Type form # global_properties. Else, guess Type by suffix id (eg: List, Date,...) list_field_type_list = ('ListField', 'MultiListField', 'LinesField',) date_field_type_list = ('DateTimeField',) suffix_mapping = {'List' : list_field_type_list, 'Date' : date_field_type_list} field_type = field_dict.get('erp_type', suffix_mapping.get(suffix, [''])[0]) if def_usePropertySheet: # generating PropertySheet and Document, no need to use them to # get field data if field_type in list_field_type_list: TALES = "python: %s " % ', '.join( "here.get%s()" % convertToUpperCase(cell_name[prefix_len:])) elif field_type in date_field_type_list: attributes_dict = field_dict['attributes'] # assign the property input_order input_order = attributes_dict['input_order'] input_order = input_order.replace('y', 'Y') # make the Tales according to the cases date_pattern = '/'.join(['%%%s' % s for s in list(input_order)]) if not(attributes_dict['date_only']): date_pattern += ' %H:%M' TALES = "python: here.get%s() is not None and here.get%s().strftime('%s') or ''"\ % (convertToUpperCase(cell_name[prefix_len:]), convertToUpperCase(cell_name[prefix_len:]), date_pattern) else: TALES = "python: here.get%s()" %\ convertToUpperCase(cell_name[prefix_len:]) else: if field_type in list_field_type_list: TALES = "python: %s" % ', '.join( "here.getProperty('%s')" % cell_name[prefix_len:]) elif field_type in date_field_type_list: attributes_dict = field_dict['attributes'] # assign the property input_order input_order = attributes_dict['input_order'] input_order = input_order.replace('y', 'Y') # make the Tales according to the cases date_pattern = '/'.join(['%%%s' % s for s in list(input_order)]) if not(attributes_dict['date_only']): date_pattern += ' %H:%M' TALES = "python: here.getProperty('%s') is not None and here.getProperty('%s').strftime('%s') or ''"\ % (cell_name[prefix_len:], cell_name[prefix_len:], date_pattern) else: TALES = "python: here.getProperty('%s')" % cell_name[prefix_len:] pdf_form.setCellTALES(cell_name, TALES) import_scribus_file.close() pdf_file.close() self.REQUEST.RESPONSE.setHeader('Content-Type', 'application/pdf') return pdf_form
def generateParsedScribus(): import_scribus_file = StringIO.StringIO(scribus_form.getData()) scribus_parser = ScribusParser(import_scribus_file) import_scribus_file.close() return scribus_parser.getERP5PropertyDict()