I just put it in it's own file in the modules directory and called it
"custom_exporter.py" You will need to put this at the top of the file:
from gluon.sqlhtml import ExportClass
When I want to use it in a controller with SQLFORM.grid, I must first
import it at the top of the controller file:
from custom_exporter import ExporterCSVlabel
then when defining the grid, give it the parameter
exportclasses=dict(csv=(ExporterCSVlabel, 'CSV'),
csv_with_hidden_cols=False, tsv=False, tsv_with_hidden_cols=False,
xml=False, html=False, json=False)
What that does is define the new ExporterCSVlabel to handle csv downloads
and disables all other exports.
You should also consider looking at gluon.sqlhtml so you can see the how
the other exporters work.
On Mon, Jul 18, 2016 at 2:42 PM, Sneka R <[email protected]> wrote:
> I am new to web2py. Which file should I make these changes?
> Thanks.
>
>
> On Friday, July 15, 2016 at 10:45:01 PM UTC-5, Jordan Myers wrote:
>>
>> Hey everyone,
>>
>> so the default csv exporters for sqlform.grid will use the headers as the
>> 'database' names, but I would rather it use the field.label instead. For
>> example, take this table:
>>
>> db.define_table('my_table', Field('ugly_name', label='Pretty Name'))
>>
>> A sqlform.grid on my_table will display the column with the header Pretty
>> Name, but when exporting to csv, the header becomes my_table.ugly_name. Is
>> there an easy way to export to csv with the columns "as seen" i.e. with the
>> labeled names? I tried writing my own exporter, but it does not preserve
>> the searching/sorting order. I suppose I could try to implement that
>> myself, but that is a last resort.
>>
>> Thanks
>>
> --
> 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 a topic in the
> Google Groups "web2py-users" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/web2py/MR_8JzzP9o4/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> [email protected].
> For more options, visit https://groups.google.com/d/optout.
>
--
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 [email protected].
For more options, visit https://groups.google.com/d/optout.