Grid export csv

121 views
Skip to first unread message

Ryan Hood

unread,
Jul 29, 2016, 12:23:28 PM7/29/16
to web2py-users
How do you get the csv export to work in web2py grid? 

NOTE: Working with web2py version 2.14.6 and 2.14.5

Thank you,

Massimo Di Pierro

unread,
Jul 31, 2016, 2:33:19 AM7/31/16
to web2py-users
You press the button. Is this not working? What happens? What you model? What is your grid?

Ryan Hood

unread,
Aug 1, 2016, 7:28:43 AM8/1/16
to web2py-users

DB.PY

db.define_table('test',

                Field('name', 'string', length=50, notnull=True),

                Field('email', 'string', notnull=True),

                format="%(name)s")


DEFAULT.PY

    query=(db.test.id>0)

    fields=[db.test.id,db.test.name,db.test.email]

    forms=SQLFORM.grid(query=query, csv=True)

    return dict(forms=forms)


I get the following error:

<type 'exceptions.AttributeError'>

Version


web2py™Version 2.14.5-stable+timestamp.2016.04.13.22.22.13
PythonPython 2.7.9: C:\python27\python.exe (prefix: C:\python27)


Function argument list

(self=<Row {'email': 'te...@test.com', 'name': 'Ryan Hood', 'id': 1L}>, k='_extra')


It appears to be looking for an _extra parameter?


Note: This happens for both CSV and TSV exports.


Please advise.


Thank you,

Ryan

Kostas M

unread,
Aug 1, 2016, 7:51:54 AM8/1/16
to web...@googlegroups.com
I have the same problem with the CSV, HTML, TSV export buttons. The Ticket for the CSV is pasted below. The problem at least with the csv export button seems to be with the REGEX_TABLE_DOT_FIELD. Normally, this constant is defined in regex.py as:
REGEX_TABLE_DOT_FIELD = re.compile('^(\w+)\.([^.]+)$')
and previous web2py versions used it.

However, now it takes the REGEX_TABLE_DOT_FIELD definition from the base.py:
obj.REGEX_TABLE_DOT_FIELD = re.compile(
r'^' + quot % regex_ent + r'\.' + quot % regex_ent + r'$')

which is a totally different regex and it doesn't match with the table field names...


Ticket ID

127.0.0.1.2016-08-01.14-36-35.a05a56c8-5b22-42c3-a3e3-385322b5f0fe

<type 'exceptions.AttributeError'>

Version

web2py™ Version 2.14.5-stable+timestamp.2016.04.14.03.26.16
Python Python 2.7.6: /home/kmouts/Envs/prolims2_venv/bin/python2.7 (prefix: /home/kmouts/Envs/prolims2_venv)

Traceback

1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
Traceback (most recent call last):
File "/home/kmouts/PycharmProjects/prolims2/web2py/gluon/restricted.py", line 227, in restricted
exec ccode in environment
File "/home/kmouts/PycharmProjects/prolims2/web2py/applications/prolims2/controllers/muser.py", line 187, in <module>
File "/home/kmouts/PycharmProjects/prolims2/web2py/gluon/globals.py", line 417, in <lambda>
self._caller = lambda f: f()
File "/home/kmouts/PycharmProjects/prolims2/web2py/gluon/tools.py", line 4258, in f
return action(*a, **b)
File "/home/kmouts/PycharmProjects/prolims2/web2py/applications/prolims2/controllers/muser.py", line 49, in my_analyses
exportclasses=dict(csv_with_hidden_cols=False, tsv_with_hidden_cols=False)
File "/home/kmouts/PycharmProjects/prolims2/web2py/gluon/sqlhtml.py", line 3102, in smartgrid
user_signature=user_signature, **kwargs)
File "/home/kmouts/PycharmProjects/prolims2/web2py/gluon/sqlhtml.py", line 2473, in grid
raise HTTP(200, oExp.export(), **response.headers)
File "/home/kmouts/PycharmProjects/prolims2/web2py/gluon/sqlhtml.py", line 3514, in export
self.rows.export_to_csv_file(s, represent=True)
File "/home/kmouts/Envs/prolims2_venv/local/lib/python2.7/site-packages/pydal/objects.py", line 2446, in export_to_csv_file
row.append(record._extra[col])
File "/home/kmouts/Envs/prolims2_venv/local/lib/python2.7/site-packages/pydal/objects.py", line 91, in __getattr__
raise AttributeError
AttributeError

Niphlod

unread,
Aug 3, 2016, 3:51:56 PM8/3/16
to web2py-users
should be already fixed on master, anyway if you're in a hurry, set entity_quoring=False on the DAL line to make it work again (long story short, DAL now quotes everything by default and not every cog in the wheel was expecting that)

Kostas M

unread,
Aug 4, 2016, 4:11:49 AM8/4/16
to web2py-users

As you said, it works again now, by setting: entity_quoting=False

Thanks Niphlod!

Bartosz Baranowski

unread,
Oct 21, 2016, 4:54:31 PM10/21/16
to web2py-users
Niphlod,

I am using latest web2py and pydal from master branches. Any idea where is the fix? Could you please direct me to the commit?

Niphlod

unread,
Oct 24, 2016, 6:48:09 AM10/24/16
to web2py-users
never ever pull web2py AND pydal master's  and merge (unless you really know what you're doing). When using "master", at most, use web2py's one, which has the correct pointers to pydal's specific commits.

Any commit later than 15aug should work fine ^_^
Reply all
Reply to author
Forward
0 new messages