本文整理汇总了Python中pyxform.create_survey_element_from_dict函数的典型用法代码示例。如果您正苦于以下问题:Python create_survey_element_from_dict函数的具体用法?Python create_survey_element_from_dict怎么用?Python create_survey_element_from_dict使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了create_survey_element_from_dict函数的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: runTest
def runTest(self):
for filename in ["select_one_external.xlsx"]:
path_to_excel_file = os.path.join(DIR, "example_xls", filename)
#Get the xform output path:
root_filename, ext = os.path.splitext(filename)
output_path = os.path.join(
DIR, "test_output", root_filename + ".xml")
expected_output_path = os.path.join(
DIR, "test_expected_output", root_filename + ".xml")
output_csv = os.path.join(
DIR, "test_output", root_filename + ".csv")
#Do the conversion:
json_survey = pyxform.xls2json.parse_file_to_json(
path_to_excel_file)
self.assertTrue(sheet_to_csv(path_to_excel_file, output_csv, "external_choices"))
self.assertFalse(sheet_to_csv(path_to_excel_file, output_csv, "non-existant sheet"))
survey = pyxform.create_survey_element_from_dict(json_survey)
survey.print_xform_to_file(output_path)
#Compare with the expected output:
with codecs.open(expected_output_path, 'rb', encoding="utf-8") as\
expected_file:
with codecs.open(output_path, 'rb', encoding="utf-8") as \
actual_file:
self.assertMultiLineEqual(
expected_file.read(), actual_file.read())
开发者ID:SEL-Columbia,项目名称:pyxform,代码行数:29,代码来源:select_one_external_test.py
示例2: runTest
def runTest(self):
for filename in [
"new_cascading_select.xls",
"old_cascades.xls",
"cascading_select_test.xls",
]:
self.get_file_path(filename)
expected_output_path = os.path.join(
DIR, "test_expected_output", self.root_filename + ".xml"
)
# Do the conversion:
json_survey = pyxform.xls2json.parse_file_to_json(self.path_to_excel_file)
survey = pyxform.create_survey_element_from_dict(json_survey)
survey.print_xform_to_file(self.output_path)
# Compare with the expected output:
with codecs.open(
expected_output_path, "rb", encoding="utf-8"
) as expected_file:
with codecs.open(
self.output_path, "rb", encoding="utf-8"
) as actual_file:
self.assertXFormEqual(expected_file.read(), actual_file.read())
开发者ID:XLSForm,项目名称:pyxform,代码行数:26,代码来源:new_cascading_select_test.py
示例3: runTest
def runTest(self):
filename = "search_and_select.xlsx"
path_to_excel_file = os.path.join(DIR, "example_xls", filename)
# Get the xform output path:
root_filename, ext = os.path.splitext(filename)
output_path = os.path.join(DIR, "test_output", root_filename + ".xml")
expected_output_path = os.path.join(DIR, "test_expected_output",
root_filename + ".xml")
# Do the conversion:
warnings = []
json_survey = pyxform.xls2json.parse_file_to_json(
path_to_excel_file, warnings=warnings)
survey = pyxform.create_survey_element_from_dict(json_survey)
survey.print_xform_to_file(output_path, warnings=warnings)
# Compare with the expected output:
with codecs.open(expected_output_path, 'rb', encoding="utf-8") \
as expected_file:
with codecs.open(output_path, 'rb', encoding="utf-8") \
as actual_file:
self.assertMultiLineEqual(
expected_file.read(), actual_file.read())
# cleanup
os.remove(output_path)
开发者ID:SEL-Columbia,项目名称:pyxform,代码行数:25,代码来源:xlsform_spec_test.py
示例4: json_workbook
def json_workbook(request):
error = None
warningsList = []
if not (os.access(SERVER_TMP_DIR, os.F_OK)):
os.mkdir(SERVER_TMP_DIR)
# Make a randomly generated directory to prevent name collisions
temp_dir = tempfile.mkdtemp(dir=SERVER_TMP_DIR)
form_name = request.POST.get("name", "form")
output_filename = form_name + ".xml"
out_path = os.path.join(temp_dir, output_filename)
if os.access(out_path, os.F_OK):
os.remove(out_path)
try:
json_survey = xls2json.workbook_to_json(
json.loads(request.POST["workbookJson"]), form_name=form_name, warnings=warningsList
)
survey = pyxform.create_survey_element_from_dict(json_survey)
survey.print_xform_to_file(out_path, warnings=warningsList)
except Exception as e:
error = str(e)
return HttpResponse(
json.dumps(
{"dir": os.path.split(temp_dir)[-1], "name": output_filename, "error": error, "warnings": warningsList},
indent=4,
),
mimetype="application/json",
)
开发者ID:uw-ictd,项目名称:pyxform_interface,代码行数:29,代码来源:views.py
示例5: runTest
def runTest(self):
for filename in ["select_one_external.xlsx"]:
self.get_file_path(filename)
expected_output_path = os.path.join(
DIR, "test_expected_output", self.root_filename + ".xml"
)
output_csv = os.path.join(DIR, "test_output", self.root_filename + ".csv")
# Do the conversion:
json_survey = pyxform.xls2json.parse_file_to_json(self.path_to_excel_file)
self.assertTrue(
sheet_to_csv(self.path_to_excel_file, output_csv, "external_choices")
)
self.assertFalse(
sheet_to_csv(self.path_to_excel_file, output_csv, "non-existant sheet")
)
survey = pyxform.create_survey_element_from_dict(json_survey)
survey.print_xform_to_file(self.output_path)
# Compare with the expected output:
with codecs.open(
expected_output_path, "rb", encoding="utf-8"
) as expected_file:
with codecs.open(
self.output_path, "rb", encoding="utf-8"
) as actual_file:
self.assertXFormEqual(expected_file.read(), actual_file.read())
开发者ID:XLSForm,项目名称:pyxform,代码行数:30,代码来源:select_one_external_test.py
示例6: runTest
def runTest(self):
for filename in ["new_cascading_select.xls", "old_cascades.xls",
"cascading_select_test.xls"]:
path_to_excel_file = os.path.join(DIR, "example_xls", filename)
# Get the xform output path:
root_filename, ext = os.path.splitext(filename)
output_path = os.path.join(
DIR, "test_output", root_filename + ".xml")
expected_output_path = os.path.join(
DIR, "test_expected_output", root_filename + ".xml")
# Do the conversion:
json_survey = pyxform.xls2json.parse_file_to_json(
path_to_excel_file)
survey = pyxform.create_survey_element_from_dict(json_survey)
survey.print_xform_to_file(output_path)
# Compare with the expected output:
with codecs.open(expected_output_path, 'rb', encoding="utf-8") as\
expected_file:
with codecs.open(output_path, 'rb', encoding="utf-8") as \
actual_file:
self.assertXFormEqual(expected_file.read(),
actual_file.read())
开发者ID:ivangayton,项目名称:pyxform,代码行数:25,代码来源:new_cascading_select_test.py
示例7: runTest
def runTest(self):
files_to_test = ["instance_xmlns_test.xls"]
for file_to_test in files_to_test:
path_to_excel_file = utils.path_to_text_fixture(file_to_test)
# Get the xform output path:
directory, filename = os.path.split(path_to_excel_file)
root_filename, ext = os.path.splitext(filename)
path_to_output_xform = os.path.join(
directory, root_filename + "_output.xml")
path_to_expected_xform = os.path.join(
directory, root_filename + ".xml")
# Do the conversion:
json_survey = xls2json.parse_file_to_json(path_to_excel_file)
survey = pyxform.create_survey_element_from_dict(json_survey)
survey.print_xform_to_file(path_to_output_xform)
# Compare with the expected output:
with codecs.open(path_to_expected_xform, 'rb', encoding="utf-8"
) as expected_file:
expected = ETree.fromstring(expected_file.read())
result = ETree.fromstring(survey.to_xml())
def write_line(x): sys.stdout.write(x + "\n")
reporter = write_line
self.assertTrue(xml_compare(
expected, result, reporter=reporter))
os.remove(path_to_output_xform)
开发者ID:ivangayton,项目名称:pyxform,代码行数:29,代码来源:tests_by_file.py
示例8: runTest
def runTest(self):
filename = "ODKValidateWarnings.xlsx"
path_to_excel_file = os.path.join(DIR, "bug_example_xls", filename)
# Get the xform output path:
root_filename, ext = os.path.splitext(filename)
output_path = os.path.join(DIR, "test_output", root_filename + ".xml")
# Do the conversion:
warnings = []
json_survey = pyxform.xls2json.parse_file_to_json(path_to_excel_file, warnings=warnings)
survey = pyxform.create_survey_element_from_dict(json_survey)
survey.print_xform_to_file(output_path, warnings=warnings)
开发者ID:sparkplug,项目名称:pyxform,代码行数:11,代码来源:bug_tests.py
示例9: index
def index(request):
if request.method == 'POST': # If the form has been submitted...
form = UploadFileForm(request.POST, request.FILES) # A form bound to the POST data
if form.is_valid(): # All validation rules pass
error = None
warnings = None
filename, ext = os.path.splitext(request.FILES['file'].name)
#Make a randomly generated directory to prevent name collisions
temp_dir = tempfile.mkdtemp(dir=SERVER_TMP_DIR)
xml_path = os.path.join(temp_dir, filename + '.xml')
#Init the output xml file.
fo = open(xml_path, "wb+")
fo.close()
try:
#TODO: use the file object directly
xls_path = handle_uploaded_file(request.FILES['file'], temp_dir)
warnings = []
json_survey = xls2json.parse_file_to_json(xls_path, warnings=warnings)
survey = pyxform.create_survey_element_from_dict(json_survey)
survey.print_xform_to_file(xml_path, warnings=warnings)
except Exception as e:
error = 'Error: ' + str(e)
return render_to_response('upload.html', {
'form': UploadFileForm(),
'xml_path' : '.' + xml_path,
'xml_url' : request.build_absolute_uri('.' + xml_path),
'success': not error,
'error': error,
'warnings': warnings,
'result': True,
})
else:
form = UploadFileForm() # An unbound form
return render_to_response('upload.html', {
'form': form,
})
开发者ID:GeoODK,项目名称:pyxform_interface,代码行数:44,代码来源:views.py
示例10: runTest
def runTest(self):
filename = "widgets.xls"
self.get_file_path(filename)
expected_output_path = os.path.join(
DIR, "test_expected_output", self.root_filename + ".xml"
)
# Do the conversion:
warnings = []
json_survey = pyxform.xls2json.parse_file_to_json(
self.path_to_excel_file, warnings=warnings
)
survey = pyxform.create_survey_element_from_dict(json_survey)
survey.print_xform_to_file(self.output_path, warnings=warnings)
# print warnings
# Compare with the expected output:
with codecs.open(expected_output_path, "rb", encoding="utf-8") as expected_file:
with codecs.open(self.output_path, "rb", encoding="utf-8") as actual_file:
self.assertXFormEqual(expected_file.read(), actual_file.read())
开发者ID:XLSForm,项目名称:pyxform,代码行数:19,代码来源:xlsform_spec_test.py
示例11: runTest
def runTest(self):
path_to_excel_file = utils.path_to_text_fixture("xlsform_spec_test.xls")
#Get the xform output path:
directory, filename = os.path.split(path_to_excel_file)
root_filename, ext = os.path.splitext(filename)
path_to_xform = os.path.join(directory, root_filename + ".xml")
#Do the conversion:
json_survey = xls2json.parse_file_to_json(path_to_excel_file)
survey = pyxform.create_survey_element_from_dict(json_survey)
survey.print_xform_to_file(path_to_xform)
#Compare with the expected output:
expected_path = utils.path_to_text_fixture("spec_test_expected_output.xml")
with codecs.open(expected_path, 'rb', encoding="utf-8") as expected_file:
expected = etree.fromstring(expected_file.read())
result = etree.fromstring(survey.to_xml())
self.assertTrue(xml_compare(expected, result))
开发者ID:Topol,项目名称:pyxform,代码行数:20,代码来源:xlsform_spec_test.py
示例12: runTest
def runTest(self):
filename = "default_time_demo.xls"
path_to_excel_file = os.path.join(DIR, "bug_example_xls", filename)
# Get the xform output path:
root_filename, ext = os.path.splitext(filename)
output_path = os.path.join(DIR, "test_output", root_filename + ".xml")
expected_output_path = os.path.join(
DIR, "test_expected_output", root_filename + ".xml"
)
# Do the conversion:
warnings = []
json_survey = pyxform.xls2json.parse_file_to_json(
path_to_excel_file, warnings=warnings
)
survey = pyxform.create_survey_element_from_dict(json_survey)
survey.print_xform_to_file(output_path, warnings=warnings)
# print warnings
# Compare with the expected output:
with codecs.open(expected_output_path, "rb", encoding="utf-8") as expected_file:
with codecs.open(output_path, "rb", encoding="utf-8") as actual_file:
self.assertXFormEqual(expected_file.read(), actual_file.read())
开发者ID:XLSForm,项目名称:pyxform,代码行数:21,代码来源:bug_tests.py
示例13: json_workbook
def json_workbook(request):
error = None
warningsList = []
#Make a randomly generated directory to prevent name collisions
temp_dir = tempfile.mkdtemp(dir=SERVER_TMP_DIR)
form_name = request.POST.get('name', 'form')
output_filename = form_name + '.xml'
out_path = os.path.join(temp_dir, output_filename)
fo = open(out_path, "wb+")
fo.close()
try:
json_survey = xls2json.workbook_to_json(json.loads(request.POST['workbookJson']), form_name=form_name, warnings=warningsList)
survey = pyxform.create_survey_element_from_dict(json_survey)
survey.print_xform_to_file(out_path, warnings=warningsList)
except Exception as e:
error = str(e)
return HttpResponse(json.dumps({
'dir': os.path.split(temp_dir)[-1],
'name' : output_filename,
'error': error,
'warnings': warningsList,
}, indent=4), mimetype="application/json")
开发者ID:GeoODK,项目名称:pyxform_interface,代码行数:22,代码来源:views.py
示例14: index
def index(request):
if request.method == "POST": # If the form has been submitted...
form = UploadFileForm(request.POST, request.FILES) # A form bound to the POST data
if form.is_valid(): # All validation rules pass
error = None
warnings = None
filename, ext = os.path.splitext(request.FILES["file"].name)
if not (os.access(SERVER_TMP_DIR, os.F_OK)):
os.mkdir(SERVER_TMP_DIR)
# Make a randomly generated directory to prevent name collisions
temp_dir = tempfile.mkdtemp(dir=SERVER_TMP_DIR)
xml_path = os.path.join(temp_dir, filename + ".xml")
itemsets_url = None
relpath = os.path.relpath(xml_path, SERVER_TMP_DIR)
# Init the output xml file.
fo = open(xml_path, "wb+")
fo.close()
try:
# TODO: use the file object directly
xls_path = handle_uploaded_file(request.FILES["file"], temp_dir)
warnings = []
json_survey = xls2json.parse_file_to_json(xls_path, warnings=warnings)
survey = pyxform.create_survey_element_from_dict(json_survey)
survey.print_xform_to_file(xml_path, warnings=warnings)
if has_external_choices(json_survey):
# Create a csv for the external choices
itemsets_csv = os.path.join(os.path.split(xls_path)[0], "itemsets.csv")
relpath_itemsets_csv = os.path.relpath(itemsets_csv, SERVER_TMP_DIR)
choices_exported = sheet_to_csv(xls_path, itemsets_csv, "external_choices")
if not choices_exported:
warnings += ["Could not export itemsets.csv, " "perhaps the external choices sheet is missing."]
else:
itemsets_url = request.build_absolute_uri("./downloads/" + relpath_itemsets_csv)
except Exception as e:
error = "Error: " + str(e)
return render_to_response(
"upload.html",
{
"form": UploadFileForm(),
"xml_path": request.build_absolute_uri("./downloads/" + relpath),
"xml_url": request.build_absolute_uri("./downloads/" + relpath),
"itemsets_url": itemsets_url,
"success": not error,
"error": error,
"warnings": warnings,
"result": True,
},
)
else:
form = UploadFileForm() # An unbound form
return render_to_response("upload.html", {"form": form})
开发者ID:uw-ictd,项目名称:pyxform_interface,代码行数:61,代码来源:views.py
注:本文中的pyxform.create_survey_element_from_dict函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论