db.define_table('evaluation',
Field('form', type='text',
label=T('Evaluation form')),
Field('results', type='text',
label=T('JSON results')),
auth.signature,
format='%(form)s',
migrate=settings.migrate)
db.evaluation.results.filter_in = lambda obj, dumps=dumps: dumps(obj)
db.evaluation.results.filter_out = lambda txt, loads=loads: loads(txt)
db.export_to_csv_file(open('test.csv', 'w'))
89,se2,"{u'name': u'Good User', u'answers': {u'q1': u'5', u'comment1': u""This answer should've had an apostrophe.""}, u'email': u'u...@mail.com'}",<auth fields>
db.import_from_csv_file(open('test.csv', 'r'))
{"name": "Good User", "answers": {"q1": "5", "comment1": "This answer should've had an apostrophe."}, "email": "u...@mail.com"}
"{u'name': u'Good User', u'answers': {u'q1': u'5', u'comment1': u\"This answer should've had an apostrophe.\"}, u'email': u'u...@mail.com'}"
evaluation.results['name']),
TypeError: string indices must be integers
After using import_from_csv_file(), additional quotes are showing up in the db.Should I be using some different quoting in export_to_csv_file() or is this an inherent problem with specifying filter_out in in the model, or am I completely off the mark?Exporting db = 2.4.6
Importing db = 2.5.1
Table definition
db.define_table('evaluation',
Field('form', type='text',
label=T('Evaluation form')),
Field('results', type='text',
label=T('JSON results')),
auth.signature,
format='%(form)s',
migrate=settings.migrate)
db.evaluation.results.filter_in = lambda obj, dumps=dumps: dumps(obj)
db.evaluation.results.filter_out = lambda txt, loads=loads: loads(txt)Export
db.export_to_csv_file(open('test.csv', 'w'))(Excerpt from test.csv)
89,se2,"{u'name': u'Good User', u'answers': {u'q1': u'5', u'comment1': u""This answer should've had an apostrophe.""}, u'email': u'...@mail.com'}",<auth fields>
Import
db.import_from_csv_file(open('test.csv', 'r'))MySQL row.results from within current application on original and new db
{"name": "Good User", "answers": {"q1": "5", "comment1": "This answer should've had an apostrophe."}, "email": "u...@mail.com"}MySQL row.results from import on new db (note the new enclosing double quotes)
"{u'name': u'Good User', u'answers': {u'q1': u'5', u'comment1': u\"This answer should've had an apostrophe.\"}, u'email': u'...@mail.com'}"
After using import_from_csv_file(), additional quotes are showing up in the db.Should I be using some different quoting in export_to_csv_file() or is this an inherent problem with specifying filter_out in in the model, or am I completely off the mark?Exporting db = 2.4.6
Importing db = 2.5.1
Table definition
db.define_table('evaluation',
Field('form', type='text',
label=T('Evaluation form')),
Field('results', type='text',
label=T('JSON results')),
auth.signature,
format='%(form)s',
migrate=settings.migrate)
db.evaluation.results.filter_in = lambda obj, dumps=dumps: dumps(obj)
db.evaluation.results.filter_out = lambda txt, loads=loads: loads(txt)Export
db.export_to_csv_file(open('test.csv', 'w'))(Excerpt from test.csv)
89,se2,"{u'name': u'Good User', u'answers': {u'q1': u'5', u'comment1': u""This answer should've had an apostrophe.""}, u'email': u'...@mail.com'}",<auth fields>
Import
db.import_from_csv_file(open('test.csv', 'r'))MySQL row.results from within current application on original and new db
{"name": "Good User", "answers": {"q1": "5", "comment1": "This answer should've had an apostrophe."}, "email": "u...@mail.com"}MySQL row.results from import on new db (note the new enclosing double quotes)
"{u'name': u'Good User', u'answers': {u'q1': u'5', u'comment1': u\"This answer should've had an apostrophe.\"}, u'email': u'...@mail.com'}"