[web2py] Re: can a filename be suggested in a custom Exporter class for a SQLFORM.grid?

2015-08-10 Thread Yoel Benitez Fonseca
Here is my solution, idk if this is corrent or not:

class CustomExporter(ExportClass):
label = ''
file_ext = ''
content_type = ''
file_name = ''

def __init__(self, rows):
super(CustomExporter, self).__init__(rows)
request = current.request
request.vars._export_filename = self.file_name or request.function

class ExporterPDF(CustomExporter):
label = 'PDF'
file_ext = "pdf"
content_type = "application/pdf"

def __init__(self, rows):
super(ExporterPDF, self).__init__(rows)

def export(self):
request = current.request
response = current.response
pdf = MyFPDF()
pdf.add_page()
pdf.add_font('dejavu','', 
'/agis/static/fonts/DejaVuSansCondensed.ttf')
pdf.add_font('dejavu','B', 
'/agis/static/fonts/DejaVuSansCondensed-Bold.ttf')
pdf.set_font('dejavu', '', 12)
filename = '%s/%s.pdf' % (request.controller,request.function)
if os.path.exists(os.path.join(request.folder,'views',filename)):
html=response.render(filename, dict(rows=self.rows))
else:
html=BODY(BEAUTIFY(response._vars)).xml()
pass
pdf.write_html(html)
return XML(pdf.output(dest='S'))

In this case is my own recipie for generic PDF exporting, using 
view_file.pdf as a template and request.function as the default filename 
for the exported file name.

El lunes, 10 de agosto de 2015, 14:49:23 (UTC-4), Yoel Benitez Fonseca 
escribió:
>
> In sqlhtml.py:
>
> class ExportClass(object):
> label = None
> file_ext = None
> content_type = None
>
> def __init__(self, rows):
> self.rows = rows
> ...
>
> Is there a way to suggest a filename to the client ?
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: can a filename be suggested in a custom Exporter class for a SQLFORM.grid?

2015-08-10 Thread Yoel Benitez Fonseca
on sqlhtml.py line 2394:

...
oExp = clazz(rows)
export_filename = \
request.vars.get('_export_filename') or 'rows'
filename = '.'.join((export_filename, oExp.file_ext))
response.headers['Content-Type'] = oExp.content_type
response.headers['Content-Disposition'] = \
'attachment;filename=' + filename + ';'
...

seems to be the code responsible for the download filename, and it is 
trying to find a filename suggestion on *request.vars.get('_export_filename') 
*!?

El lunes, 10 de agosto de 2015, 14:49:23 (UTC-4), Yoel Benitez Fonseca 
escribió:
>
> In sqlhtml.py:
>
> class ExportClass(object):
> label = None
> file_ext = None
> content_type = None
>
> def __init__(self, rows):
> self.rows = rows
> ...
>
> Is there a way to suggest a filename to the client ?
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: can a filename be suggested in a custom Exporter class for a SQLFORM.grid?

2015-08-10 Thread Yoel Benitez Fonseca
i'm allways getting rows.EXT

El lunes, 10 de agosto de 2015, 14:49:23 (UTC-4), Yoel Benitez Fonseca 
escribió:
>
> In sqlhtml.py:
>
> class ExportClass(object):
> label = None
> file_ext = None
> content_type = None
>
> def __init__(self, rows):
> self.rows = rows
> ...
>
> Is there a way to suggest a filename to the client ?
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.