Skip to content

Instantly share code, notes, and snippets.

@dorey
Created November 25, 2013 10:07
Show Gist options
  • Save dorey/7639161 to your computer and use it in GitHub Desktop.
Save dorey/7639161 to your computer and use it in GitHub Desktop.
for later reference: this avoids writing to the filesystem and allows you to pass the form_name in through the settings
import pyxform
from StringIO import StringIO
def csv_to_survey(csv_txt):
csv_io = StringIO(csv_txt)
workbook_repr = pyxform.xls2json_backends.csv_to_dict(csv_io)
try:
form_name = workbook_repr['settings'][0][u'id_string']
except KeyError, e:
form_name = "xform"
json_repr = pyxform.xls2json.workbook_to_json(workbook_repr, "PREVIEW_%s" % form_name)
survey = pyxform.create_survey_element_from_dict(json_repr)
return survey
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment