Пример #1
0
def closing_pdf(request, key=""):
    report = Report.objects.get(key=key)
    closing = Closing.objects.get(report_id=report.report_id)
    enumeration = Enumeration.objects.get(report_id=report.report_id)
    car = report.car
    contract = report.contract
    customer = contract.customer
    qrcode = get_qrc_code(qr_company=report.pdf_qr_code_company)
    context = {
        'enumeration':
        enumeration,
        'closing':
        closing,
        'report':
        report,
        'qrcode':
        check_qr_code(qrcode),
        'contract':
        contract,
        'car':
        car,
        'customer':
        customer,
        'qrcode_some':
        QRcode.qrcode(
            "http://e-otsenka.uz/pdf/{id}".format(id=report.report_id))
    }

    pdf = generate_pdf(default_template="closing.html",
                       css_name="finish_report.css",
                       context=context)
    reponse = FileResponse(ContentFile(pdf), content_type='application/pdf')
    return reponse
Пример #2
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")
Пример #3
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)
Пример #4
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")
Пример #5
0
 def create_second_pdf(self, number_pages: int) -> ContentFile:
     holds_images = self.report_model.holds_images
     images = holds_images.image.all()
     passport = holds_images.pp_photo.all()
     checks = holds_images.checks.first()
     other_photos = holds_images.o_images.all()
     document_photo = Documents.objects.first()
     from DTPreport import settings as s
     context = {
         'number_of_pages': number_pages,
         's': s.BASE_URL,
         'images': images,
         'document_photo': document_photo,
         'passport': passport,
         'checks': checks,
         'other_photos': other_photos,
     }
     from pdf_report.utils import generate_pdf
     pdf = generate_pdf(context=context, default_template="disposable.html",
                        css_name="report.css")
     return ContentFile(pdf)
Пример #6
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()
Пример #7
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