Changeset 112:e22eeb00aa5a
- Timestamp:
- 01/27/09 13:36:35 (4 years ago)
- Author:
- Ga?tan de Menten <ged@…>
- Branch:
- default
- Message:
-
do not use the report repository in any example except a special purpose
example "demo_repository".
- Files:
-
- 1 added
- 6 modified
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
|
r45
|
r112
|
|
| 13 | 13 | \HL |
| 14 | 14 | {% for line in o.lines%} \ |
| 15 | | \NC $line.item.name \VL $line.item.reference \VL $line.quantity |
| | 15 | \NC $line.item.name \VL $line.item.reference \VL $line.quantity |
| 16 | 16 | \VL $line.item.price \VL $line.amount \SR |
| 17 | 17 | \HL \ |
-
|
r85
|
r112
|
|
| 1 | | import relatorio |
| 2 | | |
| 3 | 1 | class Invoice(dict): |
| 4 | 2 | |
| … |
… |
|
| 12 | 10 | |
| 13 | 11 | |
| 14 | | repos = relatorio.ReportRepository() |
| 15 | 12 | inv = Invoice(customer={'name': 'John Bonham', |
| 16 | 13 | 'address': {'street': 'Smirnov street', |
| … |
… |
|
| 42 | 39 | bottle=(file('bouteille.png', 'r'), 'image/png')) |
| 43 | 40 | |
| 44 | | |
| 45 | | |
-
|
r80
|
r112
|
|
| 1 | | from cStringIO import StringIO |
| 2 | | from common import Invoice, repos, inv |
| | 1 | from os.path import abspath |
| | 2 | from relatorio import Report |
| 3 | 3 | |
| 4 | | repos.add_report(Invoice, 'image/png', 'pie_chart', report_name='pie') |
| 5 | | repos.add_report(Invoice, 'image/svg', 'vbar_chart', report_name='vbar') |
| 6 | | repos.add_report(Invoice, 'image/svg', 'hbar_chart', report_name='hbar') |
| 7 | | repos.add_report(Invoice, 'image/png', 'line_chart', report_name='line') |
| | 4 | # test data |
| | 5 | from common import inv |
| 8 | 6 | |
| 9 | 7 | if __name__ == '__main__': |
| 10 | | pie_report, _ = repos.classes[Invoice].ids['pie'] |
| | 8 | pie_report = Report(abspath('pie_chart'), 'image/png') |
| 11 | 9 | file('pie.png', 'wb').write(pie_report(o=inv).render().getvalue()) |
| 12 | | hbar_report, _ = repos.classes[Invoice].ids['hbar'] |
| | 10 | hbar_report = Report(abspath('hbar_chart'), 'image/svg') |
| 13 | 11 | file('hbar.svg', 'wb').write(hbar_report(o=inv).render().getvalue()) |
| 14 | | vbar_report, _ = repos.classes[Invoice].ids['vbar'] |
| | 12 | vbar_report = Report(abspath('vbar_chart'), 'image/svg') |
| 15 | 13 | file('vbar.svg', 'wb').write(vbar_report(o=inv).render().getvalue()) |
| 16 | | line_report, _ = repos.classes[Invoice].ids['line'] |
| | 14 | line_report = Report(abspath('line_chart'), 'image/png') |
| 17 | 15 | file('line.png', 'wb').write(line_report(o=inv).render().getvalue()) |
-
|
r80
|
r112
|
|
| 1 | | from cStringIO import StringIO |
| 2 | | from common import Invoice, repos, inv |
| | 1 | from os.path import abspath |
| | 2 | from relatorio import Report |
| 3 | 3 | |
| 4 | | repos.add_report(Invoice, 'application/pdf', 'basic.tex', |
| 5 | | report_name='ConTeXt') |
| | 4 | # test data |
| | 5 | from common import inv |
| | 6 | |
| 6 | 7 | #PDF |
| 7 | 8 | if __name__ == '__main__': |
| 8 | | pdf_report, _ = repos.classes[Invoice].ids['ConTeXt'] |
| 9 | | file('bonham_basic.pdf', 'wb').write(pdf_report(o=inv).render().getvalue()) |
| | 9 | print "generating output_basic.pdf... ", |
| | 10 | report = Report(abspath('basic.tex'), 'application/pdf') |
| | 11 | content = report(o=inv).render().getvalue() |
| | 12 | file('output_basic.pdf', 'wb').write(content) |
| | 13 | print "done" |
| 10 | 14 | |
-
|
r107
|
r112
|
|
| 1 | | from cStringIO import StringIO |
| 2 | | from common import Invoice, repos, inv |
| 3 | | import demo_chart |
| | 1 | from os.path import abspath |
| | 2 | from relatorio import Report |
| 4 | 3 | |
| 5 | | repos.add_report(Invoice, 'application/vnd.oasis.opendocument.text', |
| 6 | | 'basic.odt', report_name='basic') |
| 7 | | repos.add_report(Invoice, 'application/vnd.oasis.opendocument.text', |
| 8 | | 'invoice.odt', report_name='complicated') |
| 9 | | repos.add_report(Invoice, 'application/vnd.oasis.opendocument.spreadsheet', |
| 10 | | 'pivot.ods', report_name='pivot') |
| 11 | | repos.add_report(Invoice, 'application/vnd.oasis.opendocument.presentation', |
| 12 | | 'presentation.odp', report_name='presentation') |
| 13 | | repos.add_report(None, 'application/vnd.oasis.opendocument.text', |
| 14 | | 'columns.odt', report_name='column') |
| | 4 | # test data |
| | 5 | from common import inv |
| | 6 | |
| | 7 | ODT_MIME = 'application/vnd.oasis.opendocument.text' |
| | 8 | ODS_MIME = 'application/vnd.oasis.opendocument.spreadsheet' |
| | 9 | ODP_MIME = 'application/vnd.oasis.opendocument.presentation' |
| 15 | 10 | |
| 16 | 11 | if __name__ == '__main__': |
| 17 | | # Add a chart to the invoice |
| 18 | | inv['chart'] = repos.classes[Invoice].ids['pie'] |
| 19 | | |
| 20 | 12 | # ODT |
| 21 | 13 | print "generating output_basic.odt... ", |
| 22 | | basic_report, _ = repos.classes[Invoice].ids['basic'] |
| 23 | | data = basic_report(o=inv).render().getvalue() |
| 24 | | file('output_basic.odt', 'wb').write(data) |
| | 14 | report = Report(abspath('basic.odt'), ODT_MIME) |
| | 15 | content = report(o=inv).render().getvalue() |
| | 16 | file('output_basic.odt', 'wb').write(content) |
| 25 | 17 | print "done" |
| 26 | 18 | |
| | 19 | # we could also use an opendocument template directly |
| | 20 | # from relatorio.templates import opendocument |
| | 21 | # template = opendocument.Template(source=None, filepath='basic.odt') |
| | 22 | # content = template.generate(o=inv).render().getvalue() |
| | 23 | # file('output_basic.odt', 'wb').write(content) |
| | 24 | |
| 27 | 25 | print "generating output_complicated.odt... ", |
| 28 | | report, _ = repos.classes[Invoice].ids['complicated'] |
| 29 | | data = report(o=inv).render().getvalue() |
| 30 | | file('output_complicated.odt', 'wb').write(data) |
| | 26 | # Add a chart to the invoice |
| | 27 | inv['chart'] = (Report(abspath('pie_chart'), 'image/png'), 'image/png') |
| | 28 | report = Report(abspath('complicated.odt'), ODT_MIME) |
| | 29 | content = report(o=inv).render().getvalue() |
| | 30 | file('output_complicated.odt', 'wb').write(content) |
| 31 | 31 | print "done" |
| 32 | 32 | |
| 33 | 33 | print "generating output_columns.odt... ", |
| 34 | | column_report, _ = repos.classes[None].ids['column'] |
| | 34 | report = Report(abspath('columns.odt'), ODT_MIME) |
| 35 | 35 | lst = [[], ['i'], ['a', 'b'], [1, 2, 3], ['I', 'II', 'III', 'IV']] |
| 36 | 36 | titles = ['first', 'second', 'third', 'fourth'] |
| 37 | | data = column_report(titles=titles, lst=lst).render().getvalue() |
| 38 | | file('output_columns.odt', 'wb').write(data) |
| | 37 | content = report(titles=titles, lst=lst).render().getvalue() |
| | 38 | file('output_columns.odt', 'wb').write(content) |
| 39 | 39 | print "done" |
| 40 | 40 | |
| 41 | 41 | # ODS |
| 42 | 42 | print "generating output_pivot.ods... ", |
| 43 | | ods_report, _ = repos.classes[Invoice].ids['pivot'] |
| 44 | | data = ods_report(o=inv).render().getvalue() |
| 45 | | file('output_pivot.ods', 'wb').write(data) |
| | 43 | report = Report(abspath('pivot.ods'), ODS_MIME) |
| | 44 | content = report(o=inv).render().getvalue() |
| | 45 | file('output_pivot.ods', 'wb').write(content) |
| 46 | 46 | print "done" |
| 47 | 47 | |
| 48 | 48 | # ODP |
| 49 | 49 | print "generating output_presentation.odp... ", |
| 50 | | odp_report, _ = repos.classes[Invoice].ids['presentation'] |
| 51 | | data = odp_report(o=inv).render().getvalue() |
| 52 | | file('output_presentation.odp', 'wb').write(data) |
| | 50 | report = Report(abspath('presentation.odp'), ODP_MIME) |
| | 51 | content = report(o=inv).render().getvalue() |
| | 52 | file('output_presentation.odp', 'wb').write(content) |
| 53 | 53 | print "done" |
| 54 | 54 | |
-
|
r72
|
r112
|
|
| 11 | 11 | # This program is distributed in the hope that it will be useful, but WITHOUT |
| 12 | 12 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
| 13 | | # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
| | 13 | # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
| 14 | 14 | # details. |
| 15 | 15 | # |