示例#1
0
    def post(self, request, *args, **kwargs):

        uiu = {k:v for k, v in request.POST.iteritems() if 'uiu' in k}
        personal_data = {k:v for k, v in request.POST.iteritems() if
                         'urbutm' not in k and 'uiu' not in k}
        urbanistic_plans = [k for k, v in request.POST.iteritems() if
                            'urbutm' in k and v == 'on']

        cdu_doc = cdu.document.Document(uiu, urbanistic_plans, personal_data)
        html_template = cdu_doc.create_html_document()
        if html_template:
            context = {'urbanistic_names': urbanistic_plans}
            pdf = PDFTemplateResponse(request=request,
                                      template='cdu/'+html_template,
                                      filename="cdu.pdf",
                                      context=context,
                                      show_content_in_browser=False)
            pdf.render()
            cdu_doc.remove_html_document()
            response = HttpResponse(content=pdf, content_type='application/pdf')
            response['Content-Disposition'] = 'attachment; filename="cdu.pdf"'
            return response

        else:
            #TODO:: adjust not intersections response
            #return HttpResponse('Non ci sono intersezioni')
            response = HttpResponse(content='json',
                                    content_type='text/javascript')
            return response
示例#2
0
    def post(self, request, *args, **kwargs):

        uiu = {k: v for k, v in request.POST.iteritems() if 'uiu' in k}
        personal_data = {
            k: v
            for k, v in request.POST.iteritems()
            if 'urbutm' not in k and 'uiu' not in k
        }
        urbanistic_plans = [
            k for k, v in request.POST.iteritems()
            if 'urbutm' in k and v == 'on'
        ]

        cdu_doc = cdu.document.Document(uiu, urbanistic_plans, personal_data)
        html_template = cdu_doc.create_html_document()
        if html_template:
            context = {'urbanistic_names': urbanistic_plans}
            pdf = PDFTemplateResponse(request=request,
                                      template='cdu/' + html_template,
                                      filename="cdu.pdf",
                                      context=context,
                                      show_content_in_browser=False)
            pdf.render()
            cdu_doc.remove_html_document()
            response = HttpResponse(content=pdf,
                                    content_type='application/pdf')
            response['Content-Disposition'] = 'attachment; filename="cdu.pdf"'
            return response

        else:
            #TODO:: adjust not intersections response
            #return HttpResponse('Non ci sono intersezioni')
            response = HttpResponse(content='json',
                                    content_type='text/javascript')
            return response
示例#3
0
 def render(self, context, request):
     template = get_template("reports/reports_pdf.html")
     template_response = PDFTemplateResponse(
         request=request,
         template=template,
         filename="test.pdf",
         context=context,
         show_content_in_browser=False,
         cmd_options={
             "javascript-delay": 3000,
         },
     )
     template_response.render()
     content = template_response.rendered_content
     return HttpResponse(content, content_type="application/pdf")
示例#4
0
def send_invoice(invoice):
    """
    Sends Invoice to the invoice partner
    """

    template = EmailTemplate.objects.get(name='invoice-email')
    subject         = replace_invoice_vars(template.subject, invoice, 'en')
    message_plain   = replace_invoice_vars(template.plain_text, invoice, 'en')
    message_html    = replace_invoice_vars(template.html_text, invoice, 'en')

    partner_email = invoice.partner.partner_email or invoice.partner.finance_email


    # make email
    msg = EmailMultiAlternatives(
        subject=subject,
        body=message_plain,
        from_email='*****@*****.**',
        to=[partner_email, ],
        bcc=['*****@*****.**'],
    )
    msg.attach_alternative(message_html, 'text/html')

    # make Invoice PDF
    cmd_options = {
        'orientation': 'landscape',
        'page-size': 'A4',
        'title': invoice.invoice_nr
    }

    template = 'adventures/invoice/invoice_pdf.html'
    context = {
        'invoice': invoice,
        'partner': invoice.partner,
    }

    pdf_data = PDFTemplateResponse(request=None, template=template, context=context, filename=invoice.invoice_nr, show_content_in_browser=True, cmd_options=cmd_options)
    pdf_data.render()
    pdf_data.close()

    filename = "{} invoice Adventure Tickets {}.pdf".format(invoice.created.strftime("%Y-%m-%d"), invoice.invoice_nr)
    msg.attach(filename, pdf_data.rendered_content, 'application/pdf')
    msg.send()
    logger.info("Invoice sent to {}: {}".format(partner_email, str(invoice)))