/
simple-report.txt
84 lines (64 loc) · 3.02 KB
/
simple-report.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
A Simple Report
===============
This is just a simple report, that uses the Geraldo API to format a report with
the begin, summary, page header, page footer and detail bands::
import os
cur_dir = os.path.dirname(os.path.abspath(__file__))
from django.contrib.auth.models import Permission
from reportlab.lib.pagesizes import A4
from reportlab.lib.units import cm
from reportlab.lib.enums import TA_CENTER, TA_RIGHT
from geraldo import Report, ReportBand, Label, ObjectValue, SystemField,\
FIELD_ACTION_COUNT, BAND_WIDTH
class PermissionsReport(Report):
title = 'Permissions list'
class band_begin(ReportBand):
height = 1*cm
elements = [
Label(text='Look those permissions please', top=0.1*cm,
left=8*cm),
]
class band_summary(ReportBand):
height = 0.7*cm
elements = [
Label(text="That's all", top=0.1*cm, left=0),
ObjectValue(attribute_name='name', top=0.1*cm, left=3*cm,
action=FIELD_ACTION_COUNT,
display_format='%s permissions found'),
]
borders = {'all': True}
class band_page_header(ReportBand):
height = 1.3*cm
elements = [
SystemField(expression='%(report_title)s', top=0.1*cm,
left=0, width=BAND_WIDTH, style={'fontName': 'Helvetica-Bold',
'fontSize': 14, 'alignment': TA_CENTER}),
Label(text="ID", top=0.8*cm, left=0),
Label(text="Name", top=0.8*cm, left=3*cm),
]
borders = {'bottom': True}
class band_page_footer(ReportBand):
height = 0.5*cm
elements = [
Label(text='Created with Geraldo Reports', top=0.1*cm, left=0),
SystemField(expression='Page # %(page_number)d of %(page_count)d', top=0.1*cm,
width=BAND_WIDTH, style={'alignment': TA_RIGHT}),
]
borders = {'top': True}
class band_detail(ReportBand):
height = 0.5*cm
elements = [
ObjectValue(attribute_name='id', top=0, left=0),
ObjectValue(attribute_name='name', top=0, left=3*cm, width=7*cm),
]
Below you can see how to instantiate it from a permissions list
>>> report = PermissionsReport(queryset=Permission.objects.order_by('id'))
Generating PDF...
>>> from geraldo.generators import PDFGenerator
>>> report.generate_by(PDFGenerator, filename=os.path.join(cur_dir, 'output/simple-report.pdf'))
Generating Text...
>>> from geraldo.generators import TextGenerator
>>> report.generate_by(TextGenerator, filename=os.path.join(cur_dir, 'output/simple-report.txt'), to_printer=False, encode_to='latin-1')
The Result
- http://geraldo.svn.sourceforge.net/viewvc/geraldo/examples/simple-report.pdf
- http://geraldo.svn.sourceforge.net/viewvc/geraldo/examples/simple-report.txt