views.py 文件源码

python
阅读 24 收藏 0 点赞 0 评论 0

项目:infonex_crm 作者: asterix135 项目源码 文件源码
def call_report(request):
    event_assignment = get_object_or_404(EventAssignment,
                                         pk=request.session['assignment_id'])
    event = event_assignment.event
    user = request.user
    contact_history = Contact.objects.filter(
        event=event, author=user
    ).order_by('-date_of_contact')
    response = HttpResponse(content_type='application/pdf')
    response['Content-Disposition'] = 'inline; filename="call_report.pdf"'
    buffr = BytesIO()

    styles = getSampleStyleSheet()
    cell_style = styles['BodyText']
    cell_style.alignment = TA_LEFT

    report_details = []
    title = Paragraph('Call Note Report', styles['title'])
    report_details.append(title)
    conf_details_text = event.number + ': ' + event.title + ' (' \
        + user.username+ ')'
    report_details.append(Paragraph(conf_details_text, styles['h2']))
    report = SimpleDocTemplate(buffr, pagesize=letter,
                               leftMargin=inch/2, rightMargin = inch/2)
    data = []
    for contact in contact_history:
        person = contact.person.name
        if contact.person.title:
            person = person + '<br/>' + contact.person.title
        if contact.person.company:
            person = person + '<br/>' + contact.person.company
        date = Paragraph(str(contact.date_of_contact.date()), cell_style)
        person = Paragraph(person, cell_style)
        notes = Paragraph(contact.notes[:3500], cell_style)
        data.append([date, person, notes])
        table = Table(data, [inch, 3 * inch, 4.5 * inch])
        table.setStyle(TableStyle([('VALIGN', (0,0), (-1, -1), 'TOP')]))
        report_details.append(table)
        data = []
    # if len(data) > 0:
    #     call_detail_table = Table(data, [inch, 2 * inch, 4.5 * inch])
    #     call_detail_table.setStyle(TableStyle([('VALIGN', (0,0),
    #                                             (-1, -1), 'TOP')]))
    #     report_details.append(call_detail_table)


    report.build(report_details)

    pdf = buffr.getvalue()
    buffr.close()
    response.write(pdf)
    return response
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号