Skip to content

Commit

Permalink
update for compatibility with pyxform 1 (fixes #6)
Browse files Browse the repository at this point in the history
  • Loading branch information
sheppard committed Sep 2, 2020
1 parent d9d2dcc commit eab6013
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 5 deletions.
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
language: python
sudo: false
python:
- "3.4"
- "3.5"
- "3.6"
- "3.7"
- "3.8"
env:
- LINT=
- LINT=1
Expand Down
2 changes: 2 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
8 changes: 7 additions & 1 deletion xlsconv/django.py
Original file line number Diff line number Diff line change
Expand Up @@ -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('-', '_')
Expand Down
9 changes: 8 additions & 1 deletion xlsconv/html.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']:
Expand Down
8 changes: 6 additions & 2 deletions xlsconv/parser.py
Original file line number Diff line number Diff line change
@@ -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']
Expand All @@ -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'] = [
Expand Down

0 comments on commit eab6013

Please sign in to comment.