Skip to content

Commit

Permalink
Updated appreport lib to version v0.1.0, and moved to this project mo…
Browse files Browse the repository at this point in the history
…dules and classes specific of web2py framework, implemented news helpers REPORTPISA and REPORTPYFPDF, added a new example to remote reports using xmlrpc, changed structure of plugin in directory modules/plugin_appreport, and more updates.
  • Loading branch information
Lucas D'Avila committed Jun 26, 2011
1 parent 14ee249 commit 2133fe5
Show file tree
Hide file tree
Showing 8 changed files with 93 additions and 124 deletions.
23 changes: 0 additions & 23 deletions controllers/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,26 +51,3 @@ def call():
"""
session.forget()
return service()


def report():
session.forget()
return service()

import xmlrpclib

@service.xmlrpc
def pdf(view_name, username = '', args = {}, *_args, **kargs):

if not view_name:
raise Exception('Invalid view_name')
if not isinstance(view_name, str):
raise Exception('View_name must be string')
if not isinstance(username, str):
raise Exception('Username must be string')
elif not isinstance(args, dict):
raise Exception('Invalid args')

report = xmlrpclib.Binary(plugin_appreport.REPORTJASPER(view_name = view_name, args = args))

return dict(report_name = '%s_%s.pdf'%(view_name, username), report = report)
40 changes: 38 additions & 2 deletions controllers/person.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def simple_report():

if form.accepts(request.vars, session):
#build a report based on table fields (aka auto generates html) and filters informed in form
return plugin_appreport.REPORTPISA(table = person, title = 'List of persons', args = dict(form.vars))
return plugin_appreport.REPORTPISA(table = person, args = dict(form.vars))

return dict(form = form)

Expand All @@ -40,7 +40,6 @@ def complex_report():
return dict(form = form)



def custom_report():

html = """<html>
Expand Down Expand Up @@ -71,3 +70,40 @@ def custom_report():
#build a report based on static html
return plugin_appreport.REPORTPISA(html = html)
#or return plugin_appreport.REPORTPYFPDF(html = html, title = 'my custom report using the plugin appreport')


def remote_report():
session.forget()
return service()


import xmlrpclib

@service.xmlrpc
def pdf(html, **kargs):
"""
Connect a xml-rpc client, to build remote reports,
ex (python client):
import xmlrpclib
server = xmlrpclib.ServerProxy('http://localhost:8000/plugin-appreport/person/remote_report/xmlrpc')
report = server.pdf(html = '<html><body><h1>My first report</h1><table><tr><td>Hello world :P </td></tr><tr><td>using appreport and xmlrpc</td></tr><table></body></html>')['report']
report_file = open('/home/your_user_name/remote_report.pdf', 'w')
report_file.write(report.data)
report_file.close()
#now check your report on '/home/your_user_name/remote_report.pdf'
"""

if not isinstance(html, str):
raise Exception('html arg must be string')
elif html.strip() == '':
raise Exception('html arg can not be empty')


report = xmlrpclib.Binary(plugin_appreport.REPORTPISA(html = html))

return dict(report = report)
58 changes: 32 additions & 26 deletions models/plugin_appreport.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
# return plugin_appreport.REPORTPISA(table = db.table_name, filter = dict(form.vars))
#
# return dict(form = form)
#
# more info check the project wiki on github https://github.com/lucasdavila/web2py-appreport/wiki

import modules.plugin_appreport as plugin_appreport_module

Expand All @@ -30,10 +32,7 @@ def REPORTFORM(self, table):
return plugin_appreport_module.form_report_web2py.FormReportWeb2py(table = table).get_form()


# def REPORT(self, table = None, filter = '', html = '', engine = 'pisa', charset = 'utf-8', title = 'Report', orientation = 'P', unit = 'mm', format = 'A4'):
def REPORT(self, **kargs):

engine = kargs.get('engine', 'pyfpdf')
def REPORT(self, engine = 'pyfpdf', **kargs):

if engine == 'pisa':
return REPORTPISA(**kargs)
Expand All @@ -47,21 +46,18 @@ def _fix_kargs(self, kargs):
if not kargs.get('user_name'):
kargs.update({'user_name' : auth.user.first_name if 'auth' in globals() and auth.user is not None else ''})
return kargs



def _get_report_instance(self, kargs):
if kargs.get('html', '').strip() != '':
return plugin_appreport_module.libs.appreport.report.ReportHtml(**kargs)
else:
return plugin_appreport_module.report_web2py.ReportHtmlDbWeb2py(**kargs)
def __build_report(self, path_reports, pdf_builder):
return plugin_appreport_module.report_factory_web2py.ReportFactoryWeb2py(response = response, request = request, path_reports = path_reports, pdf_builder = pdf_builder).dumps()


def REPORTPISA(self, **kargs):
def REPORTPISA(self, table = None, filter = {}, html = '', **kargs):
"""
You can pass the html manually *or* pass a table and a filter to automatically generate the html (based on table field and filtered using the filter :P )
Argument types:
Expected argument:
- filter (or args): dict(form.vars) or {'table_name.field_name':'value', 'table_name.field2_name':'value2'}
- table: db.your_table
- html: string containing html and css
Expand All @@ -71,37 +67,47 @@ def REPORTPISA(self, **kargs):
"""
kargs = self._fix_kargs(kargs)
pdf_builder = plugin_appreport_module.libs.appreport.pdf_builder.PdfBuilderPisa(report = self._get_report_instance(kargs))
return self.__build_report(self._path_reports, pdf_builder)

if html.strip() != '':
report = plugin_appreport_module.libs.appreport.report.ReportHtml(html = html, **kargs)
else:
report = plugin_appreport_module.report_web2py.ReportHtmlDbWeb2py(table = table, filter = filter, **kargs)

def REPORTPYFPDF(self, **kargs):
"""
pdf_builder = plugin_appreport_module.libs.appreport.pdf_builder.PdfBuilderPisa(report = report)
return self.__build_report(self._path_reports, pdf_builder)

You can pass the html manually *or* pass a table and a filter to automatically generate the html (based on table field and filtered using the filter :P )

Argument types:
def REPORTPYFPDF(self, table = None, filter = {}, html = '', charset = 'utf-8', title = 'Report', orientation = 'P', unit = 'mm', format = 'A4', **kargs):
"""
Expected arguments:
- filter (or args): dict(form.vars) or {'table_name.field_name':'value', 'table_name.field2_name':'value2'}
- table: db.your_table
- html: string containing html
Arguments supported by pyfpdf:
You can pass the html manually *or* pass a table and a filter to automatically generate the html (based on table field and filtered using the filter :P )
Notes:
- if you pass the html (aka != '') the report will be generated manually using html *ignoring* the table and filters
- css are not supported in pyfpdf, to customize the report, see the arguments explanation below
Other arguments supported by pyfpdf:
- charset = 'utf-8'
- title = 'title of report'
- orientation = 'P' (for portrait (retrato)) or ('L' for landscape (paisagem))
- unit = 'mm'
- format = 'A4'
Notes:
- if you pass the html (aka != '') the report will be generated manually using html *ignoring* the table and filters
- css are not supported in pyfpdf, to customize the report, see the arguments explanation below
"""
kargs = self._fix_kargs(kargs)
pdf_builder = plugin_appreport_module.libs.appreport.pdf_builder.PdfBuilderPyfpdf(report = self._get_report_instance(kargs))
return self.__build_report(self._path_reports, pdf_builder)


def __build_report(self, path_reports, pdf_builder):
return plugin_appreport_module.report_factory_web2py.ReportFactoryWeb2py(response = response, request = request, path_reports = path_reports, pdf_builder = pdf_builder).dumps()
if html.strip() != '':
report = plugin_appreport_module.libs.appreport.report.ReportHtml(html = html, charset = charset, title = title, orientation = orientation, unit = unit, format = format, **kargs)
else:
report = plugin_appreport_module.report_web2py.ReportHtmlDbWeb2py(table = table, filter = filter, charset = charset, title = title, orientation = orientation, unit = unit, format = format, **kargs)

pdf_builder = plugin_appreport_module.libs.appreport.pdf_builder.PdfBuilderPyfpdf(report = self._get_report_instance(kargs))
return self.__build_report(self._path_reports, pdf_builder)


plugin_appreport = PluginAppreport()
11 changes: 9 additions & 2 deletions views/default/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,19 @@ <h2>Discover</h2>

<h2>Start</h2>
<ul>
<li>Download the latest version <a href="https://github.com/downloads/lucasdavila/web2py-appreport/web2py.plugin.appreport.w2p">here</a></li>
<li>Or pack the plugin contained in this application <a href="{{='http://127.0.0.1:8000/admin/default/pack_plugin/%s/appreport'%request.application}}">admin</a>.</li>
<li>Download the <a href="https://github.com/downloads/lucasdavila/web2py-appreport/web2py.plugin.appreport.w2p">latest version</a> of plugin</li>
<li>Or <a href="{{='http://127.0.0.1:8000/admin/default/pack_plugin/%s/appreport'%request.application}}">pack the plugin</a> contained in this application</li>
</ul>

<h2>Documentation</h2>
<ul>
<li><a href="https://github.com/lucasdavila/web2py-appreport/wiki/Docs-and-examples">Wiki</a> on github</li>
<li>#todo more docs</li>
</ul>

<h2>Contribute</h2>
<ul>
<li>Fork project on <a href="https://github.com/lucasdavila/web2py-appreport">github</a></li>
<li>Report issues on <a href="https://github.com/lucasdavila/web2py-appreport/issues">github issues</a></li>
</ul>

32 changes: 14 additions & 18 deletions views/person/report_persons.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,42 +5,38 @@
<meta charset="utf-8" />
</head>

<body>
<h2>Report of persons</h2>
<body>
<h2>Report of persons</h2>

<table border="0">
<thead>
<table border="0">
<tr>
<td><strong>Name</strong></td>
<td><strong>Phone</strong></td>
<td><strong>e-mail</strong></td>
</tr>
<tr>
<td></td>
<td><strong>Favorite music</strong></td>
<td><strong>Artist</strong></td>
<th><strong>Name</strong></th>
<th><strong>Phone</strong></th>
<th><strong>e-mail</strong></th>
<th><strong>Favorite music</strong></th>
<th><strong>Artist</strong></th>
</tr>

</thead>
<tbody>
{{for p in persons:}}
<tr>
<td>{{=p.name}}</td>
<td>{{=p.phone}}</td>
<td>{{=p.email}}</td>
<td></td>
<td></td>
</tr>
{{for m in p.favorite_music.select():}}
<tr>

<td></td>
<td></td>
<td></td>
<td>{{=m.title}}</td>
<td>{{=m.artist}}</td>

</tr>
{{pass}}
{{pass}}
</tbody>
</table>
</table>
</body>
</html>

Binary file not shown.
Binary file removed views/reports/jasper/report_teste.jasper
Binary file not shown.
53 changes: 0 additions & 53 deletions views/reports/jasper/report_teste.jrxml

This file was deleted.

0 comments on commit 2133fe5

Please sign in to comment.