Esempio n. 1
0
def generate_reject_project_pdf(request, productionline_id):
    filedata = open(os.path.dirname(__file__) +
                    '/templates/rml/reject.rml').read()
    template = Template(filedata)

    reject_product_records = []
    productionline = ProductionLine.objects.get(id=productionline_id)
    for productionline in productionline.children_productionlines:
        reject_product_records.extend(
            productionline.reject_product_records.all())
    code = generate_report_code(4, productionline.code)

    context = Context({
        'code': code,
        'productionline': productionline,
        'reject_product_records': reject_product_records,
    })
    rmldata = template.render(context).encode('utf-8')

    #trml2pdf
    pdfData = trml2pdf.parseString(rmldata)
    response = HttpResponse(mimetype='application/pdf')
    response.write(pdfData)
    response['Content-Disposition'] = 'attachment; filename=质量记录表.pdf'
    return response
Esempio n. 2
0
def generate_first_item_pdf(request, productionline_id):
    filedata = open(
        os.path.dirname(__file__) + '/templates/rml/first_item.rml').read()
    template = Template(filedata)

    productionline = ProductionLine.objects.get(id=productionline_id)
    code = generate_report_code(3, productionline.code)

    context = Context({
        'productionline': productionline,
        'code': code,
    })
    rmldata = template.render(context).encode('utf-8')

    #trml2pdf
    pdfData = trml2pdf.parseString(rmldata)
    response = HttpResponse(mimetype='application/pdf')
    response.write(pdfData)
    if productionline.is_item:
        filename = (
            u'%s三检实测数值记录卡' %
            productionline.manufacture_items.all()[0].code).encode('utf-8')
        filename = filename.replace(' ', '_')
    else:
        filename = '工序首件三检实测数值记录卡'
    print filename
    response['Content-Disposition'] = 'attachment; filename=%s.pdf' % filename
    return response
Esempio n. 3
0
 def pdf_render_to_response(self,
                            template_src,
                            context_dict={},
                            filename=None,
                            prompt=False):
     context_dict['filename'] = filename
     template = get_template(template_src)
     rml = template.render(context_dict)
     return trml2pdf.parseString(rml)
Esempio n. 4
0
def moj_obracun_pdf(request):
  narudzbe = Narudzba.objects.filter(narucio=request.user, created__gte=datetime.datetime.combine(datetime.datetime.today(), datetime.time.min))
  response = HttpResponse(mimetype='application/pdf')
  response['Content-Disposition'] = 'inline; filename=ispis.pdf'
  tpl = loader.get_template('rml/dnevni_obracun.rml')
  tc = {'narudzbe': narudzbe}
  tc.update(request)
  pdf = trml2pdf.parseString(tpl.render(Context(tc)).encode('utf-8'))
  response.write(pdf)
  return response
Esempio n. 5
0
def pdf_render_to_response(template, context, objekt=None):
  response = HttpResponse(mimetype='application/pdf')
  response['Content-Disposition'] = 'inline; filename=ispis.pdf'
  tpl = loader.get_template(template)
  tc = {'item': objekt}
  tc.update(context)

  pdf = trml2pdf.parseString(tpl.render(Context(tc)).encode('utf-8'))
  response.write(pdf)
  return response
Esempio n. 6
0
def order_to_pdf(request, order_id):
  try: narudzbe = Narudzba.objects.get(id=order_id)
  except: return
  response = HttpResponse(mimetype='application/pdf')
  response['Content-Disposition'] = 'inline; filename=ispis.pdf'
  tpl = loader.get_template('rml/dnevni-obracun.rml')
  tc = {'narudzbe': narudzbe}
  tc.update(context)

  pdf = trml2pdf.parseString(tpl.render(Context(tc)).encode('utf-8'))
  response.write(pdf)
  return response
Esempio n. 7
0
def generate_quality_pdf(request, productionline_id):
    filedata = open(os.path.dirname(__file__) +
                    '/templates/rml/quality.rml').read()
    template = Template(filedata)

    productionline = ProductionLine.objects.get(id=productionline_id)
    code = generate_report_code(2, productionline.code)

    records = productionline.first_child_productionline.oper_group_records.all(
    )
    page_counts = (records.count() - 7) / 9 + (1 if
                                               (records.count() - 7) % 9 != 0
                                               else 0)
    records = list(records)
    record_tables = []
    record_tables.append(records[0:7])

    for i in range(0, len(records[7:]), 9):
        try:
            record_tables.append(records[i + 7:i + 7 + 9])
        except:
            pass

    while len(record_tables[0]) < 7:
        record_tables[0].append(' ')

    for table in record_tables[1:]:
        while len(table) < 9:
            table.append(' ')

    # print record_tables
    context = Context({
        'productionline': productionline,
        'code': code,
        'first_page': record_tables[0],
        'page_counts': range(page_counts),
        'record_tables': record_tables[1:],
    })
    rmldata = template.render(context).encode('utf-8')
    #trml2pdf
    pdfData = trml2pdf.parseString(rmldata)
    response = HttpResponse(mimetype='application/pdf')
    response.write(pdfData)
    # print pdfData
    response[
        'Content-Disposition'] = 'attachment; filename=产品生产质量控制记录卡(首页).pdf'
    return response
Esempio n. 8
0
def technology_subpicture_pdf_data(operation_group_id):
    filedata = open(
        os.path.dirname(__file__) +
        '/templates/rml/technology_subpicture.rml').read()
    template = Template(filedata)
    operation_group = OperationGroup.objects.get(id=operation_group_id)
    context = Context({
        'operation_group':
        operation_group,
        'UPLOAD_ROOT':
        UPLOAD_ROOT,
        'page_number':
        operation_group.order + 1,
        'total_pages':
        operation_group.technology.operation_groups.all().count() + 1,
    })
    rmldata = template.render(context).encode('utf-8')

    #trml2pdf
    pdfData = trml2pdf.parseString(rmldata)
    return pdfData
Esempio n. 9
0
def pdf(fields):
    template = os.path.join(DATADIR, 'modulo-nic.rml')
    _input = codecs.open(template, 'r', 'utf-8').read()
    _input = _input % fields
    _input = _input.encode('utf-8')
    two_up(trml2pdf.parseString(_input))
Esempio n. 10
0
def pdf(fields):
    template = os.path.join(DATADIR, "modulo-nic.rml")
    _input = codecs.open(template, "r", "utf-8").read()
    _input = _input % fields
    _input = _input.encode("utf-8")
    two_up(trml2pdf.parseString(_input))
Esempio n. 11
0
def technology_pdf_data(technology_id):

    filedata = open(
        os.path.dirname(__file__) + '/templates/rml/technology.rml').read()
    template = Template(filedata)

    # barcode = base64.b64encode(Code128Encoder(code).get_imagedata(bar_width=1))

    technology = Technology.objects.get(id=technology_id)
    operation_group_objects = technology.operation_groups.all()
    code = generate_report_code(1, technology.code)

    # barcode = base64.b64encode(Code128Encoder(code).get_imagedata(bar_width=1))
    # barcode =

    try:
        barcode_item = Barcode.objects.get(code=technology.code,
                                           name=technology.name + 'pdf')
    except:
        barcode_item = add_barcode(technology.code, technology.name + 'pdf', 2)

    if TECHNOLOGY_REPORT_ROW != 0:
        row = TECHNOLOGY_REPORT_ROW
    else:
        row = 7

    operation_group_list = []
    for operation_record in operation_group_objects:
        operation_group_list.append(operation_record)

    total_table = []
    three_table = []
    list_length = len(operation_group_list)
    table_count = 0
    for i in xrange(0, list_length, row * 3):  #21

        try:
            table1_list = operation_group_list[i:i + row]  #7
            three_table.append(table1_list)
            table2_list = operation_group_list[i + row:i + row * 2]  #7 14
            three_table.append(table2_list)
            table3_list = operation_group_list[i + row * 2:i + row * 3]  #14 21
            three_table.append(table3_list)
            total_table.append(three_table)
            three_table = []
        except:
            pass

    for table in total_table:
        for sub_table in table:
            while len(sub_table) < row:
                sub_table.append(' ')

    #do output
    context = Context({
        'total_table':
        total_table,
        'technology':
        technology,
        'operation_group_objects':
        operation_group_objects,
        'code':
        code,
        'barcode':
        barcode_item.base64_code,
        'total_pages':
        technology.operation_groups.all().count() + 1,
    })
    rmldata = template.render(context).encode('utf-8')

    #trml2pdf
    pdfData = trml2pdf.parseString(rmldata)

    return pdfData
Esempio n. 12
0
def report_person_list_table(request):
    filedata = open(os.path.dirname(__file__) +
                    '/templates/rml/ex10.rml').read()
    template = Template(filedata)
    persons = Employee.objects.all().order_by('id')

    #personsdata
    personsdata = []
    personsdata.append(['名字', '描述', '性别', '部门'])
    for person in persons:
        data_line = []
        data_line.append(person.name)
        data_line.append(person.description)
        data_line.append(person.gender)
        # data_line.append(person.department.name)
        data_line.append(person.department)

        personsdata.append(data_line)
    personsrowHeights = '1.5cm' + ',1.5cm' * (len(personsdata) - 1)
    personscolWidths = '4cm' + ',4cm' * (len(personsdata[0]) - 1)

    #persons_gender_piechart
    persons_genders = [person.gender for person in persons]
    persons_genders_datas = []
    persons_genders_labels = list(set(persons_genders))
    for label in persons_genders_labels:
        persons_genders_datas.append(persons_genders.count(label))

    drawing = Drawing(150, 150)
    piechart = Pie()
    piechart.x = 25
    piechart.y = 25
    piechart.width = 100
    piechart.height = 100
    piechart.slices.strokeWidth = 1
    piechart.slices.fontSize = 12
    piechart.data = persons_genders_datas
    piechart.labels = persons_genders_labels
    drawing.add(piechart, '')
    drawing.add(String(10, 130, 'persons gender piechart', fontSize=16))
    piechartbinaryStuff = base64.b64encode(drawing.asString('png'))

    #person_by_department_chart
    departments = Department.objects.all().order_by('id')
    persons_department_datas = []
    persons_department_data_list = []
    for department in departments:
        persons_department_data_list.append(
            len(departments))  #len(department.departments.all())
    persons_department_data_tuple = tuple(persons_department_data_list)
    persons_department_datas.append(persons_department_data_tuple)

    drawing = Drawing(640, 300)
    barchart = VerticalBarChart()
    barchart.x = 25
    barchart.y = 80
    barchart.width = 600
    barchart.height = 150
    barchart.categoryAxis.labels.angle = 270
    barchart.categoryAxis.labels.dx = 7
    barchart.categoryAxis.labels.dy = -20
    barchart.categoryAxis.labels.fontSize = 10
    barchart.data = persons_department_datas
    barchart.categoryAxis.categoryNames = [
        department.name for department in departments
    ]
    drawing.add(barchart, '')
    drawing.add(String(120, 280, 'person by department chart', fontSize=24))
    barchartbinaryStuff = base64.b64encode(drawing.asString('png'))

    #style
    header = base64.b64encode(
        open(os.path.dirname(__file__) +
             '/templates/rml/pict/yuanto_top.png').read())
    booter = base64.b64encode(
        open(os.path.dirname(__file__) +
             '/templates/rml/pict/yt_booter.jpg').read())
    header_path = os.path.dirname(
        __file__) + '/templates/rml/pict/yuanto_top.png'
    #do output
    context = Context({
        'personsdata': personsdata,
        'personsrowHeights': personsrowHeights,
        'personscolWidths': personscolWidths,
        'piechart': piechartbinaryStuff,
        'barchart': barchartbinaryStuff,
        'header': header,
        'booter': booter,
        'header_path': header_path,
    })
    rmldata = template.render(context).encode('utf-8')

    #trml2pdf
    pdfData = trml2pdf.parseString(rmldata)
    response = HttpResponse(mimetype='application/pdf')
    response.write(pdfData)
    response['Content-Disposition'] = 'attachment; filename=output.pdf'
    return response
Esempio n. 13
0
def generate_pdf_invoice(invoicing_config,
                         invoice,
                         template_name='billing/invoice.rml.html'):
    from ikwen.conf.settings import CLUSTER_MEDIA_ROOT, MEDIA_ROOT
    context = {'invoice': invoice, 'IKWEN_MEDIA_ROOT': MEDIA_ROOT}
    weblet = get_service_instance()
    if getattr(settings, 'IS_IKWEN', False):
        try:
            invoice_service = invoice.service
            retailer = invoice_service.retailer
            if retailer:
                weblet = retailer
            iw_config = invoice_service.config  # iw stands for invoice weblet
            context['customer_config'] = iw_config
            context['company_name'] = escape(iw_config.company_name).encode(
                'ascii', 'xmlcharrefreplace')
            context['company_address'] = escape(iw_config.address).encode(
                'ascii', 'xmlcharrefreplace')
            context['company_city'] = escape(iw_config.city).encode(
                'ascii', 'xmlcharrefreplace')
            if iw_config.country:
                context['company_country'] = escape(
                    iw_config.country.name).encode('ascii',
                                                   'xmlcharrefreplace')
        except:
            pass
    member = invoice.member
    context['customer'] = member
    context['customer_name'] = escape(member.get_full_name()).encode(
        'ascii', 'xmlcharrefreplace')
    context['invoiced_to'] = escape(invoice.get_invoiced_to()).encode(
        'ascii', 'xmlcharrefreplace')
    config = weblet.config
    context['vendor'] = config
    context['vendor_address'] = escape(config.address).encode(
        'ascii', 'xmlcharrefreplace')
    context['vendor_name'] = escape(config.company_name).encode(
        'ascii', 'xmlcharrefreplace')
    for entry in invoice.entries:
        entry.label = escape(entry.item.label).encode('ascii',
                                                      'xmlcharrefreplace')
        entry.short_description = escape(entry.short_description).encode(
            'ascii', 'xmlcharrefreplace')
    if invoicing_config.logo.name and os.path.exists(
            MEDIA_ROOT + invoicing_config.logo.name):
        context['weblet_logo'] = MEDIA_ROOT + invoicing_config.logo.name
    if os.path.exists(weblet.home_folder + '/stamp.png'):
        context['stamp'] = weblet.home_folder + '/stamp.png'
    media_root = CLUSTER_MEDIA_ROOT + weblet.project_name_slug

    invoice_tpl = get_template(template_name)
    invoice_pdf_file = media_root + '/%s_Invoice_%s_%s.pdf' % (
        weblet.project_name_slug.upper(), invoice.number,
        invoice.date_issued.strftime("%Y-%m-%d"))
    d = Context(context)
    xmlstring = invoice_tpl.render(d)
    pdfstr = trml2pdf.parseString(xmlstring)
    fh = open(invoice_pdf_file, 'w')
    fh.write(pdfstr)
    fh.close()
    return invoice_pdf_file
Esempio n. 14
0
def generate_pdf_invoice(invoicing_config,
                         invoice,
                         template_name='billing/invoice.rml.html'):
    from ikwen.conf.settings import CLUSTER_MEDIA_ROOT, MEDIA_ROOT
    vendor_weblet = get_service_instance()
    context = {
        'invoice': invoice,
        'IKWEN_MEDIA_ROOT': MEDIA_ROOT,
        # LABELS
        'lbl_invoiced_to': _('Invoiced To').encode('ascii',
                                                   'xmlcharrefreplace'),
        'lbl_date_issued': _('Date issued').encode('ascii',
                                                   'xmlcharrefreplace'),
        'lbl_due_date': _('Due date').encode('ascii', 'xmlcharrefreplace'),
        'lbl_qty': _('Quantity').encode('ascii', 'xmlcharrefreplace'),
        'lbl_method': _('Method').encode('ascii', 'xmlcharrefreplace')
    }
    if getattr(settings, 'IS_IKWEN', False):
        try:
            invoice_service = invoice.service
            retailer = invoice_service.retailer
            if retailer and retailer.app.slug != DARAJA:
                vendor_weblet = retailer
            iw_config = invoice_service.config  # iw stands for invoice weblet
            context['customer_config'] = iw_config
            context['company_name'] = escape(iw_config.company_name).encode(
                'ascii', 'xmlcharrefreplace')
            context['company_address'] = escape(iw_config.address).encode(
                'ascii', 'xmlcharrefreplace')
            context['company_city'] = escape(iw_config.city).encode(
                'ascii', 'xmlcharrefreplace')
            if iw_config.country:
                context['company_country'] = escape(
                    iw_config.country.name).encode('ascii',
                                                   'xmlcharrefreplace')
        except:
            pass
    member = invoice.member
    context['customer'] = member
    context['payment_list'] = invoice.payment_set.filter(
        processor_tx_id__isnull=False)
    context['customer_name'] = escape(member.get_full_name()).encode(
        'ascii', 'xmlcharrefreplace')
    context['invoiced_to'] = escape(invoice.get_invoiced_to()).encode(
        'ascii', 'xmlcharrefreplace')
    context['invoice_status'] = escape(_(invoice.status)).encode(
        'ascii', 'xmlcharrefreplace')
    config = vendor_weblet.config
    context['vendor'] = config
    context['vendor_address'] = escape(config.address).encode(
        'ascii', 'xmlcharrefreplace')
    context['vendor_name'] = escape(config.company_name).encode(
        'ascii', 'xmlcharrefreplace')
    for entry in invoice.entries:
        entry.label = escape(entry.item.label).encode('ascii',
                                                      'xmlcharrefreplace')
        entry.short_description = escape(entry.short_description).encode(
            'ascii', 'xmlcharrefreplace')
    if invoicing_config.logo.name and os.path.exists(
            MEDIA_ROOT + invoicing_config.logo.name):
        context['weblet_logo'] = MEDIA_ROOT + invoicing_config.logo.name
    if os.path.exists(vendor_weblet.home_folder + '/stamp.jpg'):
        context['stamp'] = vendor_weblet.home_folder + '/stamp.jpg'
    media_root = CLUSTER_MEDIA_ROOT + vendor_weblet.project_name_slug + '/'

    invoice_tpl = get_template(template_name)
    invoice_pdf_file = media_root + '%s_Invoice_%s_%s.pdf' % (
        vendor_weblet.project_name_slug.upper(), invoice.number,
        invoice.date_issued.strftime("%Y-%m-%d"))
    d = Context(context)
    xmlstring = invoice_tpl.render(d)
    xmlstring = xmlstring.replace(u'\xa0', ' ').replace(u'\xe9', 'e')
    pdfstr = trml2pdf.parseString(xmlstring)
    fh = open(invoice_pdf_file, 'w')
    fh.write(pdfstr)
    fh.close()
    return invoice_pdf_file