Ejemplo n.º 1
0
def generate_pdf_report(id: int, obj):
    context = generate_pdf_base(id)
    file_name = get_name(obj.objects.last())
    return generate_pdf(context=context,
                        default_template="report.html",
                        main_template_path=file_name,
                        css_name="report.css")
Ejemplo n.º 2
0
def generate_finish_pdf(report):
    id = report.report_id
    car = report.car
    try:
        enumeration = Enumeration.objects.get(report_id=id)
    except Enumeration.DoesNotExist:
        enumeration = None
    contract = report.contract
    customer = contract.customer
    qrcode = get_qrc_code(qr_company=report.pdf_qr_code_company)
    context = {
        'car':
        car,
        'customer':
        customer,
        'enumeration':
        enumeration,
        'report':
        report,
        'qrcode':
        check_qr_code(qrcode),
        'contract':
        contract,
        'qrcode_some':
        QRcode.qrcode("{url}/pdf/{link}".format(
            url=s.URL_FILES, link=createQRcodeForReport(report))),
        # 'qrcode_some': QRcode.qrcode('https://people.ischool.berkeley.edu/~buckland/20THCENT.pdf')
    }
    file_path = get_name(TemplateMixing.objects.last())
    return generate_pdf(default_template="finishing_report.html",
                        main_template_path=file_path,
                        css_name="finish_report.css",
                        context=context)
Ejemplo n.º 3
0
def generate_pdf_enumeration(id: int, obj):
    context = generate_pdf_base(id)
    context['enumeration'] = Enumeration.objects.get(report_id=id)
    file_name = get_name(obj)
    return generate_pdf(context=context,
                        default_template="report.html",
                        main_template_path=file_name,
                        css_name="report.css")
Ejemplo n.º 4
0
def create_base64(new_report_pdf: Report):
    if new_report_pdf.pdf_report_base64 is None or new_report_pdf.pdf_report_base64 == "":
        locale.setlocale(locale.LC_ALL, 'C')
        calculation = Calculation.objects.create()
        context = {
            'calculation': calculation,
            'report': new_report_pdf,
            'car': new_report_pdf.car,
            'customer': new_report_pdf.contract.customer,
            'qrcode': check_qr_code(new_report_pdf.pdf_qr_code_user),
            'contract': new_report_pdf.contract,
        }
        file_name = get_name(TemplateAgreement.objects.last())
        data = generate_pdf(context=context,
                            default_template="aggreement_report.html",
                            main_template_path=file_name,
                            css_name="aggreement_report.css")
        filename = "%s.pdf" % new_report_pdf.car.car_number
        new_report_pdf.save_pdf(filename, data)
        with open(new_report_pdf.pdf_report.path, "rb") as file:
            encoded_string = base64.b64encode(file.read())
        new_report_pdf.pdf_report_base64 = encoded_string.decode('ascii')
        new_report_pdf.save()
Ejemplo n.º 5
0
def agreement_view(request, key):
    report = Report.objects.get(key=key)
    id = report.report_id
    calculation = Calculation.objects.get(report_id=id)
    contract = report.contract
    context = {
        'calculation': calculation,
        'report': report,
        'car': report.car,
        'customer': report.contract.customer,
        'qrcode_company': check_qr_code(report.pdf_qr_code_company),
        'contract': contract,
    }

    file_name = get_name(TemplateAgreement.objects.last())
    pdf = generate_pdf(context=context,
                       default_template="aggreement_report.html",
                       main_template_path=file_name,
                       css_name='aggreement_report.css')
    response = FileResponse(ContentFile(pdf),
                            content_type='application/pdf',
                            as_attachment=False)
    return response