def __call__(self): lab = self.context.bika_setup.laboratory self.lab_title = lab.getName() self.lab_address = lab.getPrintAddress() self.lab_email = lab.getEmailAddress() self.lab_url = lab.getLabURL() self.date = DateTime() client = logged_in_client(self.context) if client: self.client_title = client.Title() self.client_address = client.getPrintAddress() else: self.client_title = None self.client_address = None if client: clientuid = client.UID() else: clientuid = None username = self.context.portal_membership.getAuthenticatedMember().getUserName() self.querier = pretty_user_name_or_id(self.context, username) self.querier_email = pretty_user_email(self.context, username) query_id = self.request.form["query_id"] querytype = "" if query_id == "analysisrequests": querytype = "Analysis requests" self.queryout = QueryAnalysisRequests(self.context, self.request)() elif query_id == "orders": querytype = "Orders" self.queryout = QueryOrders(self.context, self.request)() elif query_id == "invoices": querytype = "Invoices" self.queryout = QueryInvoices(self.context, self.request)() else: self.queryout = "no query to out" return self.template()
def __call__(self): #import pdb #pdb.set_trace() lab = self.context.bika_setup.laboratory self.lab_title = lab.getName() self.address = lab.getPrintAddress() self.date = DateTime() username = self.context.portal_membership.getAuthenticatedMember( ).getUserName() self.reporter = pretty_user_name_or_id(self.context, username) self.reporter_email = pretty_user_email(self.context, username) report_id = self.request.form['report_id'] if report_id == 'analysesperservice': self.reportout = AnalysesPerService(self.context, self.request)() elif report_id == 'analysespersampletype': self.reportout = AnalysesPerSampleType(self.context, self.request)() elif report_id == 'analysesperclient': self.reportout = AnalysesPerClient(self.context, self.request)() elif report_id == 'analysestats': self.reportout = AnalysesTats(self.context, self.request)() elif report_id == 'analysesattachments': self.reportout = AnalysesAttachments(self.context, self.request)() else: self.reportout = "no report to out" # this works but the html is not rendered. #filename = "testing4.pdf" #ramdisk = StringIO() #pdf = pisa.CreatePDF(StringIO(self.reportout), ramdisk) #result = ramdisk.getvalue() #ramdisk.close() #if not pdf.err: # #stream file to browser # setheader = self.request.RESPONSE.setHeader # #setheader('Content-Length',len(result)) # setheader('Content-Type', 'Application/pdf') # setheader('Content-Disposition', 'inline; filename=%s' % filename) # self.request.RESPONSE.write(result) #filename = "testing4.pdf" ramdisk = StringIO() pdf = pisa.CreatePDF(self.template(), ramdisk) result = ramdisk.getvalue() ramdisk.close() if not pdf.err: #stream file to browser setheader = self.request.RESPONSE.setHeader #setheader('Content-Length',len(result)) setheader('Content-Type', 'application/pdf') #setheader('Content-Disposition', 'inline; filename=%s' % filename) #self.request.RESPONSE.write(result) thisid = self.context.invokeFactory("File", id="tmp") thisfile = self.context[thisid] from bika.lims.idserver import renameAfterCreation renameAfterCreation(thisfile) thisfile.setFile(result) self.request.RESPONSE.redirect(thisfile.absolute_url()) pisa.showLogging() """pisa.CreatePDF(self.reportout, "testing.pdf")
def __call__(self): lab = self.context.bika_setup.laboratory self.lab_title = lab.getName() self.lab_address = lab.getPrintAddress() self.lab_email = lab.getEmailAddress() self.lab_url = lab.getLabURL() self.date = DateTime() client = logged_in_client(self.context) if client: self.client_title = client.Title() self.client_address = client.getPrintAddress() else: self.client_title = None self.client_address = None if client: clientuid = client.UID() else: clientuid = None username = self.context.portal_membership.getAuthenticatedMember().getUserName() self.reporter = pretty_user_name_or_id(self.context, username) self.reporter_email = pretty_user_email(self.context, username) report_id = self.request.form["report_id"] reporttype = "" if report_id == "analysesperservice": reporttype = "Analyses per service" self.reportout = AnalysesPerService(self.context, self.request)() elif report_id == "analysespersampletype": reporttype = "Analyses per sampletype" self.reportout = AnalysesPerSampleType(self.context, self.request)() elif report_id == "analysesperclient": reporttype = "Analyses per client" self.reportout = AnalysesPerClient(self.context, self.request)() elif report_id == "analysestats": reporttype = "Analyses TATs" self.reportout = AnalysesTats(self.context, self.request)() elif report_id == "analysestats_overtime": reporttype = "Analyses TATs over time" self.reportout = AnalysesTatsOverTime(self.context, self.request)() elif report_id == "analysesattachments": reporttype = "Analyses attachments" self.reportout = AnalysesAttachments(self.context, self.request)() elif report_id == "analysesoutofrange": reporttype = "Analyses out of range" self.reportout = AnalysesOutOfRange(self.context, self.request)() elif report_id == "analysesrepeated": reporttype = "Analyses repeated" self.reportout = AnalysesRepeated(self.context, self.request)() elif report_id == "arsnotinvoiced": reporttype = "ARs not invoiced" self.reportout = ARsNotInvoiced(self.context, self.request)() elif report_id == "resultspersamplepoint": reporttype = "Results per sample point" self.reportout = ResultsPerSamplePoint(self.context, self.request)() else: self.reportout = "no report to out" # this is the good part ramdisk = StringIO() pdf = pisa.CreatePDF(self.template(), ramdisk) result = ramdisk.getvalue() ramdisk.close() # write pdf to report object reportid = self.aq_parent.generateUniqueId("Report") self.aq_parent.invokeFactory(id=reportid, type_name="Report") report = self.aq_parent._getOb(reportid) report.edit(title=reporttype, ReportFile=result, ReportType=reporttype, Client=clientuid) report.processForm() report.reindexObject() if not pdf.err: setheader = self.request.RESPONSE.setHeader setheader("Content-Type", "application/pdf") self.request.RESPONSE.write(result) pisa.showLogging() return self.template()