1
Auto expanding band height
2
==========================
4
This is an example of auto expanding function on bands. This means a band has the
5
height flexible and adapted to its elements. It is useful to print long text
6
data that can be short or long depending on the object::
9
cur_dir = os.path.dirname(os.path.abspath(__file__))
11
from reportlab.lib.pagesizes import A4
12
from reportlab.lib.units import cm
13
from reportlab.lib.enums import TA_CENTER, TA_RIGHT
15
from geraldo import Report, ReportBand, Label, ObjectValue, SystemField,\
16
FIELD_ACTION_COUNT, BAND_WIDTH
18
class SimpleReport(Report):
19
title = 'Auto Expanded Bands Report'
21
class band_begin(ReportBand):
24
Label(text='Look those permissions please', top=0.1*cm,
28
class band_summary(ReportBand):
31
Label(text="That's all", top=0.1*cm, left=0),
32
ObjectValue(attribute_name='city', top=0.1*cm, left=3*cm,\
33
action=FIELD_ACTION_COUNT, display_format='%s permissions found'),
35
borders = {'all': True}
37
class band_page_header(ReportBand):
40
SystemField(expression='%(report_title)s', top=0.1*cm, left=0, width=BAND_WIDTH,
41
style={'fontName': 'Helvetica-Bold', 'fontSize': 14, 'alignment': TA_CENTER}),
42
Label(text="ID", top=0.8*cm, left=0),
43
Label(text="Name", top=0.8*cm, left=3*cm),
45
borders = {'bottom': True}
47
class band_page_footer(ReportBand):
50
Label(text='Created with Geraldo Reports', top=0.1*cm, left=0),
51
SystemField(expression='Page # %(page_number)d of %(page_count)d', top=0.1*cm,
52
width=BAND_WIDTH, style={'alignment': TA_RIGHT}),
54
borders = {'top': True}
56
class band_detail(ReportBand):
58
auto_expand_height = True
59
margin_bottom = 0.4*cm
61
ObjectValue(attribute_name='city', top=0, left=0),
62
ObjectValue(attribute_name='country', top=0, left=5*cm, width=5*cm),
63
ObjectValue(attribute_name='about', top=0, left=10*cm, width=8*cm),
69
... {'city': 'New York', 'country': 'USA', 'about': "New York is the most populous city in the United States, and the center of the New York metropolitan area, which is among the most populous urban areas in the world. A leading global city, New York exerts a powerful influence over worldwide commerce, finance, culture, fashion and entertainment. As host of the United Nations headquarters, it is also an important center for international affairs. The city is often referred to as New York City to differentiate it from the state of New York, of which it is a part."},
70
... {'city': 'London', 'country': 'UK', 'about': "London contains four World Heritage Sites: the Tower of London; the historic settlement of Greenwich; the Royal Botanic Gardens, Kew; and the site comprising the Palace of Westminster, Westminster Abbey and St. Margaret's Church."},
71
... {'city': 'Paris', 'country': 'FR', 'about': "An important settlement for more than two millennia, Paris is today one of the world's leading business and cultural centres, and its influence in politics, education, entertainment, media, fashion, science and the arts all contribute to its status as one of the world's major global cities.[8] According to 2005 estimates, the Paris urban area is Europe's biggest city economy,[9] and is fifth in the world's list of cities by GDP."},
72
... {'city': 'Moscow', 'country': 'RU', 'about': "A person from Moscow is called a Muscovite in English, Moskvich[8] in Russian."},
75
>>> report = SimpleReport(queryset=objects_list)
79
>>> from geraldo.generators import PDFGenerator
80
>>> report.generate_by(PDFGenerator, filename=os.path.join(cur_dir, 'output/auto-expand-bands-report.pdf'))
84
- http://geraldo.svn.sourceforge.net/viewvc/geraldo/examples/auto-expand-bands-report.pdf