~grupoesoc/cubicerp-addons/7.0

« back to all changes in this revision

Viewing changes to report_geraldo/lib/geraldo/site/online/docs/_sources/examples/in-multiprocessing.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
Generating under new Process
 
2
============================
 
3
 
 
4
This is exactly the same report we made for "without-Django" test. But this is going
 
5
to be ran under an independent Process, from multiprocessing library.
 
6
 
 
7
Is important to keep aware on:
 
8
 
 
9
- multiprocessing works on Python 2.3 or higher - and is a builtin package on 2.6
 
10
- you must use 'generate_under_process_by' instead of 'generate_by'
 
11
- you can do it without 'generate_under_process_by', using geraldo.utils.run_under_process
 
12
  decorator, if you prefer do it manually
 
13
- the method ''generate_under_process_by' is not the best solution ever. You must keep
 
14
  aware on what kind of report generation you are doing, and how server is configure, but
 
15
  most of cases will work well
 
16
- the decorator 'run_under_process' will work only if geraldo.utils.DISABLE_MULTIPROCESSING
 
17
  is False
 
18
 
 
19
    >>> import os
 
20
    >>> cur_dir = os.path.dirname(os.path.abspath(__file__))
 
21
 
 
22
    >>> from geraldo.utils import A4, cm, TA_CENTER, TA_RIGHT
 
23
    
 
24
    >>> from geraldo import Report, ReportBand, Label, ObjectValue, SystemField,\
 
25
    ...     FIELD_ACTION_COUNT, BAND_WIDTH
 
26
 
 
27
Report class
 
28
 
 
29
    >>> class SimpleListReport(Report):
 
30
    ...     title = 'Demonstration without Django'
 
31
    ... 
 
32
    ...     class band_page_header(ReportBand):
 
33
    ...         height = 1.3*cm
 
34
    ...         elements = [
 
35
    ...             SystemField(expression='%(report_title)s', top=0.1*cm, left=0, width=BAND_WIDTH,
 
36
    ...                 style={'fontName': 'Helvetica-Bold', 'fontSize': 14, 'alignment': TA_CENTER}),
 
37
    ...             Label(text="ID", top=0.8*cm, left=0),
 
38
    ...             Label(text="Name", top=0.8*cm, left=3*cm),
 
39
    ...         ]
 
40
    ...         borders = {'bottom': True}
 
41
    ... 
 
42
    ...     class band_page_footer(ReportBand):
 
43
    ...         height = 0.5*cm
 
44
    ...         elements = [
 
45
    ...             Label(text='Created with Geraldo Reports', top=0.1*cm, left=0),
 
46
    ...             SystemField(expression='Page # %(page_number)d of %(page_count)d', top=0.1*cm,
 
47
    ...                 width=BAND_WIDTH, style={'alignment': TA_RIGHT}),
 
48
    ...         ]
 
49
    ...         borders = {'top': True}
 
50
    ... 
 
51
    ...     class band_detail(ReportBand):
 
52
    ...         height = 0.5*cm
 
53
    ...         elements = [
 
54
    ...             ObjectValue(attribute_name='id', top=0, left=0),
 
55
    ...             ObjectValue(attribute_name='name', top=0, left=3*cm),
 
56
    ...         ]
 
57
 
 
58
    >>> class MyObject(object):
 
59
    ...     def __init__(self, **kwargs):
 
60
    ...         for k,v in kwargs.items():
 
61
    ...             setattr(self, k, v)
 
62
 
 
63
 
 
64
    >>> objects_list = [
 
65
    ...     MyObject(id=1, name='Rio de Janeiro'),
 
66
    ...     MyObject(id=2, name='New York'),
 
67
    ...     MyObject(id=3, name='Paris'),
 
68
    ...     MyObject(id=4, name='London'),
 
69
    ...     MyObject(id=5, name='Tokyo'),
 
70
    ...     MyObject(id=6, name='Moscow'),
 
71
    ...     MyObject(id=7, name='Beijing'),
 
72
    ...     MyObject(id=8, name='Hamburg'),
 
73
    ...     MyObject(id=9, name='New Delhi'),
 
74
    ...     MyObject(id=10, name='Jakarta'),
 
75
    ... ]
 
76
 
 
77
    >>> report = SimpleListReport(queryset=objects_list)
 
78
 
 
79
PDF generation
 
80
 
 
81
    >>> from geraldo.generators import PDFGenerator
 
82
 
 
83
    >>> report.generate_under_process_by(PDFGenerator, filename=os.path.join(cur_dir, 'output/generated-in-multiprocessing.pdf'))
 
84
 
 
85