def test_reder_data_as_html(self): request = self.factory.post( '/download', data={'data': '{% lorem 1 p %}'}) data = extract_request_variables(request) self.assertIn( 'Lorem ipsum dolor sit amet', data['data'], msg="Not rendering data as html")
def test_var_empty(self): request = self.factory.post('/download', data={}) data = extract_request_variables(request) default_data = { 'pagesize': 'letter portrait', 'data': '', 'page_orientation': 'portrait', 'page_size': 'letter', 'example_number': '1', 'border': '' } self.assertDictEqual(data, default_data, msg="No default data")
def render_pdf(request): template_path = 'user_printer.html' context = extract_request_variables(request) response = HttpResponse(content_type='application/pdf') response['Content-Disposition'] = 'attachment; filename="report.pdf"' template = get_template(template_path) html = template.render(Context(context)) if request.POST.get('show_html', ''): response['Content-Type'] = 'application/text' response['Content-Disposition'] = 'attachment; filename="report.txt"' response.write(html) else: pisaStatus = pisa.CreatePDF( html, dest=response, link_callback=link_callback) if pisaStatus.err: return HttpResponse('We had some errors with code %s <pre>%s</pre>' % (pisaStatus.err, html)) return response
def render_pdf(request): template_path = 'user_printer.html' context = extract_request_variables(request) response = HttpResponse(content_type='application/pdf') response['Content-Disposition'] = 'attachment; filename="report.pdf"' template = get_template(template_path) html = template.render(context) if request.POST.get('show_html', ''): response['Content-Type'] = 'application/text' response['Content-Disposition'] = 'attachment; filename="report.txt"' response.write(html) else: pisaStatus = pisa.CreatePDF(html, dest=response, link_callback=link_callback) if pisaStatus.err: return HttpResponse( 'We had some errors with code %s <pre>%s</pre>' % (pisaStatus.err, html)) return response