~grupoesoc/cubicerp-addons/7.0

« back to all changes in this revision

Viewing changes to report_geraldo/lib/geraldo/site/newsite/site-geraldo/docs/_sources/examples/auto-expand-bands.txt

  • Committer: Cubic ERP
  • Date: 2014-01-07 15:38:09 UTC
  • Revision ID: info@cubicerp.com-20140107153809-4jmif3zoi8rcveve
[ADD] cubicReport

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
Auto expanding band height
 
2
==========================
 
3
 
 
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::
 
7
 
 
8
    import os
 
9
    cur_dir = os.path.dirname(os.path.abspath(__file__))
 
10
    
 
11
    from reportlab.lib.pagesizes import A4
 
12
    from reportlab.lib.units import cm
 
13
    from reportlab.lib.enums import TA_CENTER, TA_RIGHT
 
14
    
 
15
    from geraldo import Report, ReportBand, Label, ObjectValue, SystemField,\
 
16
         FIELD_ACTION_COUNT, BAND_WIDTH
 
17
    
 
18
    class SimpleReport(Report):
 
19
         title = 'Auto Expanded Bands Report'
 
20
     
 
21
         class band_begin(ReportBand):
 
22
             height = 1*cm
 
23
             elements = [
 
24
                 Label(text='Look those permissions please', top=0.1*cm,
 
25
                     left=8*cm),
 
26
             ]
 
27
     
 
28
         class band_summary(ReportBand):
 
29
             height = 0.7*cm
 
30
             elements = [
 
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'),
 
34
             ]
 
35
             borders = {'all': True}
 
36
     
 
37
         class band_page_header(ReportBand):
 
38
             height = 1.3*cm
 
39
             elements = [
 
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),
 
44
             ]
 
45
             borders = {'bottom': True}
 
46
     
 
47
         class band_page_footer(ReportBand):
 
48
             height = 0.5*cm
 
49
             elements = [
 
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}),
 
53
             ]
 
54
             borders = {'top': True}
 
55
     
 
56
         class band_detail(ReportBand):
 
57
             height = 0.5*cm
 
58
             auto_expand_height = True
 
59
             margin_bottom = 0.4*cm
 
60
             elements = [
 
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),
 
64
             ]
 
65
 
 
66
Objects list
 
67
 
 
68
    >>> objects_list = [
 
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."},
 
73
    ... ]
 
74
    >>> 
 
75
    >>> report = SimpleReport(queryset=objects_list)
 
76
 
 
77
PDF generation
 
78
 
 
79
    >>> from geraldo.generators import PDFGenerator
 
80
    >>> report.generate_by(PDFGenerator, filename=os.path.join(cur_dir, 'output/auto-expand-bands-report.pdf'))
 
81
 
 
82
The Result
 
83
 
 
84
- http://geraldo.svn.sourceforge.net/viewvc/geraldo/examples/auto-expand-bands-report.pdf
 
85