def _toPythonInner(self, filehandle, b, rootname): filehandle.write('\n') for n in b: kw = dict(n.attr) label = kw.pop('label', n.label) attrlist = ['u"%s"' % label] for k, v in kw.items(): if k == 'file': k = 'filepath' attrlist.append('%s="%s"' % (k, v)) if n.value: varname = slugify(label).replace('!!', '').replace('-', '_') filehandle.write(' %s = %s.branch(%s)' % (varname, rootname, ', '.join(attrlist))) self._toPythonInner(filehandle, n.value, varname) elif 'table' in kw: filehandle.write(' %s.thpage(%s)' % (rootname, ', '.join(attrlist))) elif 'lookup_manager' in kw: filehandle.write(' %s.lookups(%s)' % (rootname, ', '.join(attrlist))) elif 'pkg' in kw: filehandle.write(' %s.branch(%s)' % (rootname, ', '.join(attrlist))) else: filehandle.write(' %s.webpage(%s)' % (rootname, ', '.join(attrlist))) filehandle.write('\n')
def onUploadingAttachment(self, kwargs): attachment_table = kwargs.get('attachment_table') maintable = attachment_table[0:-4] maintable_id = kwargs.get('maintable_id') maintableobj = self.db.table(maintable) filename = kwargs.get('filename') description, ext = os.path.splitext(filename) description = slugify(description) last = self.db.table(attachment_table).query( where='$maintable_id=:mid', mid=maintable_id, order_by='_row_count desc', limit=1).fetch() counter = 0 if last: counter = last[0]['_row_count'] filename = '%002i_%s%s' % (counter, description, ext) kwargs['filename'] = filename path = os.path.join(maintable.replace('.', '_'), maintable_id) if hasattr(maintableobj, 'atc_getAttachmentPath'): path = maintableobj.atc_getAttachmentPath(pkey=maintable_id) kwargs['uploadPath'] = 'vol:%s' % path record = dict(maintable_id=maintable_id, mimetype=kwargs.get('mimetype'), description=description, filepath=os.path.join(path, filename)) self.db.table(attachment_table).insert(record) self.db.commit()
def __init__(self, docname): import xlrd import os.path self.XL_CELL_DATE = xlrd.XL_CELL_DATE self.xldate_as_tuple = xlrd.xldate_as_tuple self.docname = docname self.dirname = os.path.dirname(docname) self.basename, self.ext = os.path.splitext(os.path.basename(docname)) self.ext = self.ext.replace('.', '') self.book = xlrd.open_workbook(filename=self.docname) self.sheet = self.book.sheet_by_index(0) self.linegen = self.sheetlines() firstline = self.linegen.next() headers = [ slugify(firstline[c], sep='_') for c in range(self.sheet.ncols) ] self.colindex = dict([(i, True) for i, h in enumerate(headers) if h]) self.headers = [h for h in headers if h] self.index = dict() for i, k in enumerate(self.headers): if k in self.index: raise GnrException('Duplicated columns in source xls') self.index[k] = i self.ncols = len(headers) self.nrows = self.sheet.nrows - 1
def parseAttachment(self, part, new_mail, part_content_type=None): new_attachment = dict(message_id=new_mail["id"]) filename = part.get_filename() filename = email.Header.decode_header(filename)[0][0] filename = self.smartConverter(filename) counter = 1 if not filename: filename = "part-%03d%s" % (counter, "bin") counter += 1 if part.get_content_type().startswith("message/"): att_data = self.getMessagePayload(part) else: att_data = part.get_payload(decode=True) fname, ext = os.path.splitext(filename) fname = fname.replace(".", "_").replace("~", "_").replace("#", "_").replace(" ", "").replace("/", "_") # fname = '%i_%s' %(self.atc_counter,fname) fname = slugify(fname) self.atc_counter += 1 filename = fname + ext new_attachment["filename"] = filename date = new_mail["send_date"] attachment_path = self.getAttachmentPath(date=date, filename=filename, message_id=new_mail["id"]) # year = str(date.year) # month = '%02i' %date.month # new_attachment['path'] = os.path.join('mail',self.account_id, year,month,new_mail['id'], filename) new_attachment["path"] = self.getAttachmentPath( date=date, filename=filename, message_id=new_mail["id"], relative=True ) with open(attachment_path, "wb") as attachment_file: attachment_file.write(att_data) self.attachments_table.insert(new_attachment)
def parseAttachment(self, part, new_mail, part_content_type=None): new_attachment = dict(message_id = new_mail['id']) filename = part.get_filename() filename = email.Header.decode_header(filename)[0][0] filename = self.smartConverter(filename) counter = 1 if not filename: filename = 'part-%03d%s' % (counter, 'bin') counter += 1 if part.get_content_type().startswith('message/'): att_data = self.getMessagePayload(part) else: att_data = part.get_payload(decode=True) fname,ext = os.path.splitext(filename) fname = fname.replace('.','_').replace('~','_').replace('#','_').replace(' ','').replace('/','_') #fname = '%i_%s' %(self.atc_counter,fname) fname = slugify(fname) self.atc_counter+=1 filename = fname+ext new_attachment['filename'] = filename date = new_mail.get('send_date') or datetime.datetime.today() attachment_path = self.getAttachmentPath(date=date,filename=filename, message_id=new_mail['id']) #year = str(date.year) #month = '%02i' %date.month #new_attachment['path'] = os.path.join('mail',self.account_id, year,month,new_mail['id'], filename) new_attachment['path'] = self.getAttachmentPath(date=date,filename=filename, message_id=new_mail['id'], relative=True) with open(attachment_path,'wb') as attachment_file: attachment_file.write(att_data) self.attachments_table.insert(new_attachment)
def outputDocName(self, ext=''): maintable_obj = self.db.table(self.maintable) if ext and not ext[0] == '.': ext = '.%s' % ext caption = '' if self.getData('record'): caption = slugify(maintable_obj.recordCaption(self.getData('record'))) doc_name = '%s_%s%s' % (maintable_obj.name, caption, ext) return doc_name
def outputDocName(self, ext=''): maintable_obj = self.db.table(self.maintable) if ext and not ext[0] == '.': ext = '.%s' % ext caption = '' if self.getData('record'): caption = slugify(maintable_obj.recordCaption(self.getData('record'))) doc_name = '%s_%s%s' % (maintable_obj.name, caption, ext) return doc_name
def statspane_run_pivotTable(self, gnrpandas=None, dfname=None, name=None, pivot=None, filters=None, dest_dataframe=None, comment=None, out_html=None, out_xls=None, title=None, margins=None, counter=None, description=None, **kwargs): if out_html: title = title or 'Pivot table %s' % counter out_html = Bag(code=slugify('step_%s_%s' % (title, counter)), title=title, comment=comment or '', summary=description) if out_xls: title = title or comment or 'Pivot table' out_xls = Bag(code=slugify('step_%s_%s' % (title, counter)), title=title) pt, store = gnrpandas[dfname].pivotTableGrid(index=pivot['index'], values=pivot['values'], margins=margins, columns=pivot['columns'], filters=filters, out_html=out_html, out_xls=out_xls) result = Bag(store=store, parent_dataframe=dfname) if dest_dataframe: info = gnrpandas.registerDataFrame(dfname=dest_dataframe, dataframe=pt, comment=comment) result['newdataframe'] = Bag(store=info, dataframe_info=dest_dataframe) result['report_title'] = title result['report_description'] = title return result
def result_handler_pdf(self, resultAttr): if not self.results: return '{btc_name} completed'.format( btc_name=self.batch_title), dict() save_as = slugify( self.print_options.get('save_as') or self.batch_parameters.get('save_as') or '') if not save_as: if len(self.results) > 1: save_as = 'multiple_pfda' #slugify(self.batch_title) else: save_as = self.page.site.storageNode( self.results['#0']).cleanbasename[9:] #aggiunto [9:] per avere il record -9 caratteri iniziali outputFileNode = self.page.site.storageNode('home:proforma_ranalli', save_as, autocreate=-1) #outputFileNode=self.page.site.storageNode('/home/tommaso/Documenti/Agenzia/PROFORMA', save_as,autocreate=-1) #self.print_options.setItem('zipped', True) # settando il valore zipped a True ottengo un file zippato zipped = self.print_options.get('zipped') immediate_mode = self.batch_immediate if immediate_mode is True: immediate_mode = self.batch_parameters.get('immediate_mode') if immediate_mode and zipped: immediate_mode = 'download' if zipped: outputFileNode.path += '.zip' self.page.site.zipFiles(list(self.results.values()), outputFileNode) else: outputFileNode.path += '.pdf' self.pdf_handler.joinPdf(list(self.results.values()), outputFileNode) self.fileurl = outputFileNode.url(nocache=True, download=True) inlineurl = outputFileNode.url(nocache=True) resultAttr['url'] = self.fileurl resultAttr['document_name'] = save_as resultAttr['url_print'] = 'javascript:genro.openWindow("%s","%s");' % ( inlineurl, save_as) if immediate_mode: resultAttr['autoDestroy'] = 600 if immediate_mode == 'print': self.page.setInClientData(path='gnr.clientprint', value=inlineurl, fired=True) elif immediate_mode == 'download': self.page.setInClientData(path='gnr.downloadurl', value=inlineurl, fired=True) if outputFileNode: path_pdf = outputFileNode.internal_path
def outputDocName(self, ext=''): """add??? :param ext: add???. Default value is ``''`` :returns: add??? """ if ext and not ext[0] == '.': ext = '.%s' % ext caption = '' if self.record is not None: caption = slugify(self.tblobj.recordCaption(self.getData('record'))) doc_name = '%s_%s%s' % (self.tblobj.name, caption, ext) return doc_name
def outputDocName(self, ext=''): """TODO :param ext: TODO""" if ext and not ext[0] == '.': ext = '.%s' % ext caption = '' if self.record is not None: caption = slugify(self.tblobj.recordCaption(self.getData('record'))) idx = self.record_idx if idx is not None: caption = '%s_%i' %(caption,idx) doc_name = '%s_%s%s' % (self.tblobj.name, caption, ext) return doc_name
def outputDocName(self, ext=''): """TODO :param ext: TODO""" if ext and not ext[0] == '.': ext = '.%s' % ext caption = '' if self.record is not None: caption = slugify(self.tblobj.recordCaption(self.getData('record'))) idx = self.record_idx if idx is not None: caption = '%s_%i' %(caption,idx) doc_name = '%s_%s%s' % (self.tblobj.name, caption, ext) return doc_name
def statspane_run_pivotTable(self,gnrpandas=None,dfname=None,name=None,pivot=None,filters=None, dest_dataframe=None,comment=None,out_html=None,out_xls=None,title=None,margins=None,counter=None, description=None,**kwargs): if out_html: title = title or 'Pivot table %s' %counter out_html = Bag(code=slugify('step_%s_%s' %(title,counter)),title=title, comment=comment or '',summary=description) if out_xls: title = title or comment or 'Pivot table' out_xls = Bag(code=slugify('step_%s_%s' %(title,counter)),title=title) pt,store = gnrpandas[dfname].pivotTableGrid(index=pivot['index'],values=pivot['values'], margins=margins, columns=pivot['columns'],filters=filters,out_html=out_html, out_xls=out_xls) result = Bag(store=store,parent_dataframe=dfname) if dest_dataframe: info = gnrpandas.registerDataFrame(dfname=dest_dataframe,dataframe=pt,comment=comment) result['newdataframe'] = Bag(store=info,dataframe_info=dest_dataframe) result['report_title'] = title result['report_description'] = title return result
def onUploadingAttachment(self,kwargs): attachment_table = kwargs.get('attachment_table') maintable = attachment_table[0:-4] maintable_id = kwargs.get('maintable_id') maintableobj = self.db.table(maintable) filename = kwargs.get('filename') description,ext = os.path.splitext(filename) description = slugify(description) filename = '%s%s' %(description,ext) kwargs['filename'] = filename path = os.path.join(maintable.replace('.','_'),maintable_id) if hasattr(maintableobj,'atc_getAttachmentPath'): path = maintableobj.atc_getAttachmentPath(pkey=maintable_id) kwargs['uploadPath'] = 'vol:%s' %path record = dict(maintable_id=maintable_id,mimetype=kwargs.get('mimetype'),description=description,filepath=os.path.join(path,filename)) self.db.table(attachment_table).insert(record) self.db.commit()
def result_handler_pdf(self, resultAttr): pdfprinter = self.print_handler.getPrinterConnection( 'PDF', self.print_options) save_as = slugify(self.print_options['save_as'] or self.batch_title) filename = pdfprinter.printPdf( self.results.values(), self.batch_title, outputFilePath=self.page.site.getStaticPath('user:output', 'pdf', save_as, autocreate=-1)) if filename: self.fileurl = self.page.site.getStaticUrl('user:output', 'pdf', filename, nocache=True, download=True) resultAttr['url'] = self.fileurl resultAttr['document_name'] = save_as resultAttr[ 'url_print'] = 'javascript:genro.openWindow("%s","%s");' % ( self.page.site.getStaticUrl( 'user:output', 'pdf', filename, nocache=True), save_as) if self.batch_immediate: resultAttr['autoDestroy'] = 5 if self.batch_immediate is True: self.batch_immediate = self.batch_parameters.get( 'immediate_mode') if self.batch_immediate == 'print': self.page.setInClientData(path='gnr.clientprint', value=self.page.site.getStaticUrl( 'user:output', 'pdf', filename, nocache=True), fired=True) elif self.batch_immediate == 'download': self.page.setInClientData(path='gnr.downloadurl', value=self.page.site.getStaticUrl( 'user:output', 'pdf', filename, nocache=True), fired=True)
def result_handler_pdf(self, resultAttr): pdfprinter = self.print_handler.getPrinterConnection('PDF', self.print_options) save_as = slugify(self.print_options['save_as'] or self.batch_title) filename = pdfprinter.printPdf(self.results.values(), self.batch_title, outputFilePath=self.page.site.getStaticPath('user:output', 'pdf', save_as, autocreate=-1)) if filename: self.fileurl = self.page.site.getStaticUrl('user:output', 'pdf', filename, nocache=True, download=True) resultAttr['url'] = self.fileurl resultAttr['document_name'] = save_as resultAttr['url_print'] = 'javascript:genro.openWindow("%s","%s");' %(self.page.site.getStaticUrl('user:output', 'pdf', filename, nocache=True),save_as) if self.batch_immediate: resultAttr['autoDestroy'] = 5 if self.batch_immediate is True: self.batch_immediate = self.batch_parameters.get('immediate_mode') if self.batch_immediate=='print': self.page.setInClientData(path='gnr.clientprint',value=self.page.site.getStaticUrl('user:output', 'pdf', filename, nocache=True),fired=True) elif self.batch_immediate=='download': self.page.setInClientData(path='gnr.downloadurl',value=self.page.site.getStaticUrl('user:output', 'pdf', filename, nocache=True),fired=True)
def onUploadingAttachment(self, kwargs): attachment_table = kwargs.get('attachment_table') maintable = attachment_table[0:-4] maintable_id = kwargs.get('maintable_id') maintableobj = self.db.table(maintable) filename = kwargs.get('filename') description, ext = os.path.splitext(filename) description = slugify(description) filename = '%s%s' % (description, ext) kwargs['filename'] = filename path = os.path.join(maintable.replace('.', '_'), maintable_id) if hasattr(maintableobj, 'atc_getAttachmentPath'): path = maintableobj.atc_getAttachmentPath(pkey=maintable_id) kwargs['uploadPath'] = 'vol:%s' % path record = dict(maintable_id=maintable_id, mimetype=kwargs.get('mimetype'), description=description, filepath=os.path.join(path, filename)) self.db.table(attachment_table).insert(record) self.db.commit()
def onUploadingAttachment(self,kwargs): attachment_table = kwargs.get('attachment_table') maintable = attachment_table[0:-4] maintable_id = kwargs.get('maintable_id') maintableobj = self.db.table(maintable) filename = kwargs.get('filename') description,ext = os.path.splitext(filename) description = slugify(description) last = self.db.table(attachment_table).query(where='$maintable_id=:mid',mid=maintable_id,order_by='_row_count desc',limit=1).fetch() counter = 0 if last: counter = last[0]['_row_count'] filename = '%002i_%s%s' %(counter,description,ext) kwargs['filename'] = filename path = os.path.join(maintable.replace('.','_'),maintable_id) if hasattr(maintableobj,'atc_getAttachmentPath'): path = maintableobj.atc_getAttachmentPath(pkey=maintable_id) kwargs['uploadPath'] = 'vol:%s' %path record = dict(maintable_id=maintable_id,mimetype=kwargs.get('mimetype'),description=description,filepath=os.path.join(path,filename)) self.db.table(attachment_table).insert(record) self.db.commit()
def _toPythonInner(self,filehandle,b,rootname): filehandle.write('\n') for n in b: kw = dict(n.attr) label = kw.pop('label',n.label) attrlist = ['u"%s"' %label] for k,v in kw.items(): if k=='file': k = 'filepath' attrlist.append('%s="%s"' %(k,v)) if n.value: varname = slugify(label).replace('!!','').replace('-','_') filehandle.write(' %s = %s.branch(%s)' %(varname,rootname,', '.join(attrlist))) self._toPythonInner(filehandle,n.value,varname) elif 'table' in kw: filehandle.write(' %s.thpage(%s)' %(rootname,', '.join(attrlist))) elif 'lookup_manager' in kw: filehandle.write(' %s.lookups(%s)' %(rootname,', '.join(attrlist))) elif 'pkg' in kw: filehandle.write(' %s.branch(%s)' %(rootname,', '.join(attrlist))) else: filehandle.write(' %s.webpage(%s)' %(rootname,', '.join(attrlist))) filehandle.write('\n')
def __init__(self, docname): import xlrd import os.path self.XL_CELL_DATE = xlrd.XL_CELL_DATE self.xldate_as_tuple = xlrd.xldate_as_tuple self.docname = docname self.dirname = os.path.dirname(docname) self.basename, self.ext = os.path.splitext(os.path.basename(docname)) self.ext = self.ext.replace('.', '') self.book = xlrd.open_workbook(filename=self.docname) self.sheet = self.book.sheet_by_index(0) self.linegen = self.sheetlines() firstline = self.linegen.next() headers = [slugify(firstline[c],sep='_') for c in range(self.sheet.ncols)] self.colindex = dict([(i,True)for i,h in enumerate(headers) if h]) self.headers = [h for h in headers if h] self.index = dict() for i,k in enumerate(self.headers): if k in self.index: raise GnrException('Duplicated columns in source xls') self.index[k] = i self.ncols = len(headers) self.nrows = self.sheet.nrows - 1
def trigger_onInserting(self,record=None): getattr(self,'configDefault_%(ruleset)s' %record)(record=record) if not record['code']: code = slugify(record['title'],'')[:20] record['code'] = code.upper()
def assignCode(self, record): code = slugify(record['name'],'') record['code'] = code.upper()
def _importer_keycb(self,k): return slugify(str(k),sep='_')