[reportlab-users] Save PDF File to model using two views
Asif Jamadar
asif.jamadar at rezayat.net
Tue Jun 28 09:42:01 EDT 2011
How can I save the dynamically generated PDF report into separate django model (database) as file.
The below code works fine for me
def report(request)
response = HttpResponse(mimetype='application/pdf')
response['Content-Disposition'] = 'attachment;filename=ANALYSIS_REPORT.pdf'
buffer = StringIO()
doc = SimpleDocTemplate(buffer)
#Create the PDF
doc.build(document, onLaterPages=header_footer)
pdf = buffer.getvalue()
myfile = ContentFile(pdf)
m = Report()
m.file.save('test.pdf', myfile)
response.write(pdf)
return response
This code will saves the PDF to separate model. Here the model is 'Report'. This works fine for me.
But problem is when I use different view to save the report into model. Here is the code which gives me a error
def analysis_report(request)
response = HttpResponse(mimetype='application/pdf')
response['Content-Disposition'] = 'attachment;filename=ANALYSIS_REPORT.pdf'
buffer = StringIO()
doc = SimpleDocTemplate(buffer)
#Create the PDF
doc.build(document, onLaterPages=header_footer)
pdf = buffer.getvalue()
response.write(pdf)
return response
def save_report(request)
report = analysis_report(request)
myfile = ContentFile(report)
m = Report()
m.file.save('analysis_report.pdf', myfile)
m.report_name = "Analysis Report"
m.save()
return render_to_response(sometemplate.html)
This will throws me error "expected read buffer, HttpResponse found"
However both views should return response
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://two.pairlist.net/pipermail/reportlab-users/attachments/20110628/4980cd7f/attachment.html>
More information about the reportlab-users
mailing list