def download_bills(modeladmin, request, queryset): if queryset.count() > 1: stringio = StringIO() archive = zipfile.ZipFile(stringio, 'w') for bill in queryset: pdf = html_to_pdf(bill.html or bill.render()) archive.writestr('%s.pdf' % bill.number, pdf) archive.close() response = HttpResponse(stringio.getvalue(), content_type='application/pdf') response['Content-Disposition'] = 'attachment; filename="orchestra-bills.zip"' return response bill = queryset.get() pdf = html_to_pdf(bill.html or bill.render()) return HttpResponse(pdf, content_type='application/pdf')
def document(self, request, pk): bill = self.get_object() content_type = request.META.get('HTTP_ACCEPT') if content_type == 'application/pdf': pdf = html_to_pdf(bill.html or bill.render()) return HttpResponse(pdf, content_type='application/pdf') else: return HttpResponse(bill.html or bill.render())
def document(self, request, pk): bill = self.get_object() content_type = request.META.get("HTTP_ACCEPT") if content_type == "application/pdf": pdf = html_to_pdf(bill.html or bill.render()) return HttpResponse(pdf, content_type="application/pdf") else: return HttpResponse(bill.html or bill.render())
def send(self): html = self.html or self.render() self.account.send_email( template=settings.BILLS_EMAIL_NOTIFICATION_TEMPLATE, context={ 'bill': self, }, contacts=(Contact.BILLING,), attachments=[ ('%s.pdf' % self.number, html_to_pdf(html), 'application/pdf') ] ) self.is_sent = True self.save(update_fields=['is_sent'])
def as_pdf(self): html = self.html or self.render() return html_to_pdf(html, pagination=self.has_multiple_pages)