AppReport using web2py view.

318 views
Skip to first unread message

annet

unread,
Oct 27, 2011, 4:37:57 AM10/27/11
to web2py-users
In this thread: http://groups.google.com/group/web2py/browse_thread/thread/bb5abc07b692a554/
AppReport was mentioned. I downloaded the plugin and followed the
instructions in the Examples: https://github.com/lucasdavila/web2py-appreport/wiki/Docs-and-examples

This example results in an error:

def custom_report():
html = """
<html>
<body>
<table>
<thead>
<tr>
<th>Author</th>
<th>Email</th>
<th>Twitter</th>
</tr>
</thead>
<tbody>
<tr>
<td>Lucas Davila</td>
<td>luca...@gmail.com</td>
<td>@lucadavila</
td>
</tr>
</tbody>
</table>
</body>
</html>"""

return plugin_appreport.REPORTPYFPDF(html = html, title = 'my
custom report using the plugin appreport')


Traceback (most recent call last):
File "/Library/Python/2.5/site-packages/web2py/gluon/restricted.py",
line 192, in restricted
exec ccode in environment
File "/Library/Python/2.5/site-packages/web2py/applications/reports/
controllers/default.py", line 106, in <module>
File "/Library/Python/2.5/site-packages/web2py/gluon/globals.py",
line 145, in <lambda>
self._caller = lambda f: f()
File "/Library/Python/2.5/site-packages/web2py/applications/reports/
controllers/default.py", line 51, in custom_report
return plugin_appreport.REPORTPYFPDF(html = html, title = 'my
custom report using the plugin appreport')
File "/Library/Python/2.5/site-packages/web2py/applications/reports/
models/plugin_appreport.py", line 109, in REPORTPYFPDF
pdf_builder =
plugin_appreport_module.libs.appreport.pdf_builder.PdfBuilderPyfpdf(report
= self._get_report_instance(kargs))
AttributeError: PluginAppreport instance has no attribute
'_get_report_instance'


How would I use App Report when these are my function and view:


Controller:

def classtimesweek():

rows=db((db.lesrooster.bedrijf_id==1)&(db.lesrooster.dag_id==db.dag.id)&(db.lesrooster.level_id==db.level.id)).select(db.lesrooster.ALL,db.dag.dag,db.level.level,orderby=db.lesrooster.dag_id|
db.lesrooster.tijd)
return dict(rows=rows)

View:

<table id="init" class="display" style="margin-top: 12px;">
<thead>
...
</thead>
<tbody>
...
</tbody>
</table>



Kind regards,

Annet

Paolo Caruccio

unread,
Oct 27, 2011, 5:29:23 AM10/27/11
to web...@googlegroups.com
I have done it this way (code abstract not tested):

### model

db.define_table('t_persons',
Field('f_surname', type='string', notnull=True, label=T('Surname'), length=32),
Field('f_name', type='string', notnull=True, label=T('Name'), length=32),
)

### controller

def myreport():
persons = db(db.t_persons.id > 0).select()
logourl = URL('static','images/mylogo.jpg',host=True)
html = response.render('resources/myreport.html', dict(persons = persons, tdy=date.today(), logo=logourl))
return plugin_appreport.REPORTPISA(html = html)

### view myreport.html

<html>
<head>
<meta charset="utf-8" />
<style type="text/css">
@page {
margin: 1cm;
margin-bottom:2.5cm;
@frame footer {
-pdf-frame-content: footerContent;
/*-pdf-frame-border: 1;*/
bottom: 0cm;
margin-left: 1cm;
margin-right: 1cm;
height: 1cm;
}
}
h2 {font-width:bold;text-align:center;}
tr td{}
.section{border:1px solid #000;font-weight:bold;padding:4px 6px 0;}
.label{width:45%;}
.data{width:54%;}
</style>
</head>
<body>
<img src="{{=logo}}" alt="company logo" width="93" height="69"/>
<h2>Titolo</h2>
<table border="0" cellspacing="0" cellpadding="0" width="100%"> 
<thead>
<tr>
<td class="label">&nbsp;</td>
<td class="data">&nbsp;</td>
<td>&nbsp;</td>
</tr>
</thead>
<tbody>
{{for p in persons:}}
<tr>
<td colspan='3'>&nbsp;</td>
</tr>
<tr>
<td class="section" colspan="2">SECTION TITLE</td>
<td>&nbsp;</td>
</tr>
<tr>
<td colspan='3'>&nbsp;</td>
</tr>
<tr>
<td><strong>Surname</strong></td>
<td>{{=p.f_surname}}</td>
<td>&nbsp;</td>
</tr>
<tr>
<td><strong>Given Name</strong></td>
<td>{{=p.f_name}}</td>
<td>&nbsp;</td>
</tr>
{{pass}}
</tbody>
</table>
<div id="footerContent">
page #<pdf:pagenumber> printed on {{=tdy}}
</div>
</body>

### in view print_report.html

{{=A(SPAN(T('print report'), _class='printer_ico'), _href=URL('myreport'), _class="button")}}


Let me know if this works.

Ciao,

Paolo

annet

unread,
Oct 27, 2011, 6:57:32 AM10/27/11
to web2py-users
Hi Paolo,

Thanks for your reply, the code you provided works, I'll convert it
into my own app, hope that works too.


Kind regards,

Annet.
Reply all
Reply to author
Forward
0 new messages