Exemple #1
0
def vote_sign(request, meeting_pk=None, vote_pk=None):
    vote = get_object_or_404(Vote, pk=vote_pk)
    print 'vote_sign vote "%s"' % (vote_pk)
    pdf_name = vote_filename(vote)
    pdf_template = 'db/meetings/xhtml2pdf/vote.html'
    preview_template = 'db/meetings/xhtml2pdf/vote_preview.html'
    
    context = vote_context(vote)
    html_preview = render(request, preview_template, context).content
    pdf_data = xhtml2pdf(render(request, pdf_template, context).content)
    document_uuid = uuid4().get_hex();

    t_in = tempfile.NamedTemporaryFile(prefix='vote_sign_', suffix='.pdf', delete=False)
    t_out = tempfile.NamedTemporaryFile(prefix='vote_sign_stamped_', suffix='.pdf', delete=False)
    t_in.write(pdf_data)

    t_in.seek(0)
    pdf_barcodestamp(t_in, t_out, document_uuid)
    t_in.close()
    os.remove(t_in.name)
    
    t_out.seek(0)
    pdf_data_stamped = t_out.read()
    t_out.close()
    os.remove(t_out.name)
    
    pdfas_id = votesDepot.deposit(pdf_data_stamped, html_preview, document_uuid, pdf_name)
    return sign(request, pdfas_id, len(pdf_data_stamped), pdf_name)
Exemple #2
0
def notification_pdf(request, notification_pk=None):
    notification = get_object_or_404(Notification, pk=notification_pk)
    template_names = ['db/notifications/xhtml2pdf/%s.html' % name for name in (notification.type.form_cls.__name__, 'base')]
    tpl = loader.select_template(template_names)
    html = tpl.render(Context({
        'notification': notification,
        'investigators': notification.investigators.order_by('ethics_commission__name', 'name'),
        'url': request.build_absolute_uri(),
    }))
    pdf = xhtml2pdf(html)
    ec_num = '_'.join(str(s['ec_number']) for s in Submission.objects.filter(forms__notifications=notification).order_by('ec_number').values('ec_number'))
    response = HttpResponse(pdf, content_type='application/pdf')
    response['Content-Disposition'] = 'attachment;filename=%s.pdf' % slugify("%s-%s" % (ec_num, notification.type.name))
    return response
Exemple #3
0
def render_pdf(request, template, context):
    html = render_html(request, template, context)
    return xhtml2pdf(html)