[pyar] pyfpdf - web2py - template desde DB

Mariano Reingart reingart en gmail.com
Jue Ago 15 18:39:23 ART 2013


On Thu, Aug 15, 2013 at 5:32 PM, Luciano Bovio <omicronvt en gmail.com> wrote:
> Estoy tratando de usar un template de pyfpdf en web2py mediante la DB.
>
> Sigo los pasos del tut pero me salta este error al querer ver el template :
>
> <type 'exceptions.AttributeError'> 'Row' object has no attribute 'copy'

Esto debería estar resuelto, ver el issue en el sitio del proyecto
(abajo pongo la solución provisoria):

https://code.google.com/p/web2py/issues/detail?id=1255

> Este es el traceback:
> Traceback (most recent call last):
>   File "/home/lu/web2py/gluon/restricted.py", line 212, in restricted
>     exec ccode in environment
>   File
> "/home/lu/web2py/applications/sueldos/controllers/liquidaciones_a5.py", line
> 415, in <module>
>   File "/home/lu/web2py/gluon/globals.py", line 193, in <lambda>
>     self._caller = lambda f: f()
>   File
> "/home/lu/web2py/applications/sueldos/controllers/liquidaciones_a5.py", line
> 275, in test
>     return f.render("./template.pdf",dest='S')
>   File "/home/lu/web2py/gluon/contrib/fpdf/template.py", line 114, in render
>     element = element.copy()
> AttributeError: 'Row' object has no attribute 'copy'
> ----------------------------------------------------------------------------

La línea 114 de /home/lu/web2py/gluon/contrib/fpdf/template.py
deberías cambiarla a:

element = dict(element)

Hubo un cambio en la clase Row, por lo que se debe ajustar esa linea.

> Si uso el template harcodedeado dentro del controller anda joya.
>
> adjunto ejemplo resumido :
> -----------------------------------------------------------------------------
> def test():
> #importar
>     from gluon.contrib.pyfpdf import Template
>
> # traer elements desde la base
>     elements =
> db(db.pdf_element.pdf_template_id==1).select(orderby=db.pdf_element.priority)
> # o usar template hardcodeado
> #    elements = [{ 'name': 'box', 'type': 'B', 'x1': 5.0, 'y1': 5.0, 'x2':
> 143.5, 'y2': 205.0, 'font': 'Arial', 'size': 0.0, 'bold': 0, 'italic': 0,
> 'underline': 0, 'foreground': 0, 'background': 0, 'align': 'I', 'text':
> None, 'priority': 0, }]
>
> #crear template
>     f = Template(format="A4",
>                  title="Sample Invoice", elements=elements)
>
> #agregar página
>     f.add_page()
>
> #mostrar la página
>     response.headers['Content-Type']='application/pdf'
>     return f.render("./template.pdf",dest='S')
> -------------------------------------------------------------------------------
>
> Alguna ayuda ?
>

¿que versión de web2py y de fpdf estas usando?
Las últimas actualizaciones deberían tener este tema corregido.

Sds

Mariano Reingart
http://www.sistemasagiles.com.ar
http://reingart.blogspot.com


More information about the pyar mailing list