单击按钮django时打印多个文档

时间:2017-09-11 04:24:15

标签: python html django printing

我的问题是如何选择多个文档并打印这些文档。例如,我选择3个文档,当我单击打印按钮时,它们将在新链接中打开,所有文档必须在一个页面上。 在这个页面的顶部,我将有打印按钮。我可以通过唯一的doc_id获取每个文档,并以json格式发送文档数据,我已经编写了打印单个文档的功能,但我不知道如何在一个页面上打开多个文档,它必须是相同的?

prine several documents

print button on the top

打印单个文档的代码:

def view_signed_document(request, code):
    params = dict()
    try:
        obj = DownloadCode.objects.get(code=code)
    except:
        return render(request, 'documents/doc_not_found.html', {'code': code})
    params['Docs'] = docs
    params['pb'] = pb
    params['is_pdf'] = request.GET.get('is_pdf', 'false')
    params['code'] = code
    params['host'] = request.scheme + "://" + request.META["HTTP_HOST"]
    params['url'] = settings.SITE_URL + request.get_full_path()

    if obj.doc_type == INVOICE_TYPE:
        # Invoice proxy has different parameter names, therefore we handle it
        # in separate case.
        response = proxy.get_invoice_by_id(invoice_id=obj.doc_id, tin=obj.tin)
        if response.status.code != pb.ResponseStatus.OK:
            response = proxy.get_invoice_draft_by_id(
                invoice_draft_id=obj.doc_id, tin=obj.tin)
        params['invoice'] = response.invoice
        template = 'pdf/invoice.html'
    else:
        ref = perm.document_type_proxy[obj.doc_type]
        response = ref['get'](doc_id=obj.doc_id, tin=obj.tin)
        if response.status.code != pb.ResponseStatus.OK:
            return render(request, 'documents/doc_not_found.html', {'code': code})
        params['document'] = response.document
        params['sign_actions'] = sum(
            x.permission == docs.SIGN for x in response.document.document_actions)
        template = ref['print_template']
        if obj.doc_type == COMMONS_TYPE:
            if response.document.internal_type == docs.CommonDocument.WITH_FILES:
                template = ref['print_files_template']
    return render(request, template, params)

0 个答案:

没有答案