Created
November 25, 2013 10:07
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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