From eab60131794244834689a6ff7a45036353699633 Mon Sep 17 00:00:00 2001 From: "S. Andrew Sheppard" Date: Wed, 2 Sep 2020 15:37:44 +0900 Subject: [PATCH] update for compatibility with pyxform 1 (fixes #6) --- .travis.yml | 3 ++- setup.py | 2 ++ xlsconv/django.py | 8 +++++++- xlsconv/html.py | 9 ++++++++- xlsconv/parser.py | 8 ++++++-- 5 files changed, 25 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index 8977396..4e4cad5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,9 +1,10 @@ language: python sudo: false python: - - "3.4" - "3.5" - "3.6" + - "3.7" + - "3.8" env: - LINT= - LINT=1 diff --git a/setup.py b/setup.py index 56fe2fc..845571e 100644 --- a/setup.py +++ b/setup.py @@ -53,6 +53,8 @@ def readme(): 'Programming Language :: Python :: 3.4', 'Programming Language :: Python :: 3.5', 'Programming Language :: Python :: 3.6', + 'Programming Language :: Python :: 3.7', + 'Programming Language :: Python :: 3.8', 'Topic :: Software Development :: Code Generators', 'Framework :: Django', 'Topic :: Text Processing :: Markup :: HTML', diff --git a/xlsconv/django.py b/xlsconv/django.py index 85e75b1..bc764ed 100644 --- a/xlsconv/django.py +++ b/xlsconv/django.py @@ -81,7 +81,13 @@ def process_fields(fields): max_len = len(choice['name']) field['max_len'] = max_len - qtype = field['type_info']['bind']['type'] + if field['type'] in ('select1', 'select one'): + qtype = 'select1' + elif field['type'].startswith('select'): + qtype = 'select' + else: + qtype = field['type_info']['bind']['type'] + field['type_is_%s' % qtype] = True field['subtype_is_%s' % field['type']] = True field['field_name'] = field['name'].lower().replace('-', '_') diff --git a/xlsconv/html.py b/xlsconv/html.py index 4c53d85..3249841 100644 --- a/xlsconv/html.py +++ b/xlsconv/html.py @@ -80,7 +80,14 @@ def process_fields(fields, prefix=None, many=False): continue if 'type_info' not in field: continue - qtype = field['type_info']['bind']['type'] + + if field['type'] in ('select1', 'select one'): + qtype = 'select1' + elif field['type'].startswith('select'): + qtype = 'select' + else: + qtype = field['type_info']['bind']['type'] + if qtype == 'string': for qt in STRING_SUBTYPES: if qt in field['type']: diff --git a/xlsconv/parser.py b/xlsconv/parser.py index 8e4ad63..fa70471 100644 --- a/xlsconv/parser.py +++ b/xlsconv/parser.py @@ -1,4 +1,4 @@ -from pyxform.xls2json import parse_file_to_json +from pyxform.xls2json import parse_file_to_json, get_filename from pyxform.question_type_dictionary import QUESTION_TYPE_DICT as QTYPES GROUP_TYPES = ['group', 'repeat'] @@ -13,7 +13,11 @@ def parse_xls(file_or_name): else: fileobj = file_or_name filename = fileobj.name - xform_json = parse_file_to_json(filename, file_object=fileobj) + xform_json = parse_file_to_json( + filename, + file_object=fileobj, + default_name=get_filename(filename) + ) # Remove 'meta' field from form xform_json['children'] = [