Skip to content

Commit

Permalink
feat(templates,logic): pre-datadictionary implement;
Browse files Browse the repository at this point in the history
- Support current versions of CKAN for the DataDictionary form override for `strip_extra_white`.
- Support current versions of CKAN for existing info before existing data dictionary custom fields.
  • Loading branch information
JVickery-TBS committed Jul 16, 2024
1 parent 7cb6a84 commit bf2e939
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
6 changes: 4 additions & 2 deletions ckanext/xloader/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,8 @@ def load_csv(csv_filepath, resource_id, mimetype='text/csv', logger=None):
for f in fields:
if f['id'] in existing_info:
f['info'] = existing_info[f['id']]
f['strip_extra_white'] = existing_fields_by_headers[f['id']].get('strip_extra_white', True)
f['strip_extra_white'] = existing_info[f['id']].get('strip_extra_white') if 'strip_extra_white' in existing_info[f['id']] \
else existing_fields_by_headers[f['id']].get('strip_extra_white', True)

'''
Delete or truncate existing datastore table before proceeding,
Expand Down Expand Up @@ -459,7 +460,8 @@ def row_iterator():
for h in headers_dicts:
if h['id'] in existing_info:
h['info'] = existing_info[h['id']]
h['strip_extra_white'] = existing_fields_by_headers[h['id']].get('strip_extra_white', True)
h['strip_extra_white'] = existing_info[h['id']].get('strip_extra_white') if 'strip_extra_white' in existing_info[h['id']] \
else existing_fields_by_headers[h['id']].get('strip_extra_white', True)
# create columns with types user requested
type_override = existing_info[h['id']].get('type_override')
if type_override in list(_TYPE_MAPPING.values()):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@
{% block additional_fields %}
{{ super() }}
{% if h.check_ckan_version(min_version='2.11') %}
{{ form.select('fields__' ~ position ~ '__strip_extra_white',
label=_('Strip Extra Leading and Trailing White Space'), options=[
{'text': _('Yes'), 'value': true},
{'text': _('No'), 'value': false},
], selected=field.get('strip_extra_white')) }}
{% set field_prefix = 'fields__' %}
{% else %}
{% set field_prefix = 'info__' %}
{% endif %}
{% set is_selected = field.get('info', {}).get('strip_extra_white', field.get('strip_extra_white')) != 'False' %}
{{ form.select(field_prefix ~ position ~ '__strip_extra_white',
label=_('Strip Extra Leading and Trailing White Space'), options=[
{'text': _('Yes'), 'value': true},
{'text': _('No'), 'value': false},
], selected=is_selected) }}
{% endblock %}

0 comments on commit bf2e939

Please sign in to comment.