Skip to content
Snippets Groups Projects
Commit 6330f91b authored by Thorge Petersen's avatar Thorge Petersen
Browse files

Added helper functions for loading applicableLegislation and hvdCategory mappings

parent 80c45934
No related branches found
No related tags found
1 merge request!52Added applicableLegislation and hvdCategory support
......@@ -500,6 +500,69 @@ def short_name_for_category(category_name):
}
return translations.get(category_name)
def odsh_load_applicable_legislations():
'''
Load applicable legislations.
'''
extension_path = pkg_resources.resource_filename('ckanext.odsh', '')
default_mapping_file_path = extension_path + '/resources/applicable_legislations.json'
mapping_file_path = config.get(
'ckanext.odsh.applicable_legislations_file_path', default_mapping_file_path)
try:
with open(mapping_file_path) as mapping_json:
MAPPING = json.loads(
mapping_json.read(), object_pairs_hook=OrderedDict)
default = [{'value': 'Geltende Rechtsvorschrift wählen..', 'key': ''}]
options = [{'key': key, 'value': MAPPING[key]}
for key in MAPPING]
result = default+options
except IOError as err:
log.error(
'Could not load mapping file from {}'
.format(mapping_file_path)
)
raise
except ValueError as err:
log.error(
'Could not convert mapping file from json. \nMapping file: {}'
.format(mapping_file_path)
)
raise
return result
def odsh_load_hvd_categories():
'''
Load HVD categories.
'''
extension_path = pkg_resources.resource_filename('ckanext.odsh', '')
default_mapping_file_path = extension_path + '/resources/hvd_categories.json'
mapping_file_path = config.get(
'ckanext.odsh.hvd_categories_file_path', default_mapping_file_path)
try:
with open(mapping_file_path) as mapping_json:
MAPPING = json.loads(
mapping_json.read(), object_pairs_hook=OrderedDict)
default = [{'value': 'HVD Kategorie wählen..', 'key': ''}]
options = [{'key': key, 'value': MAPPING[key]}
for key in MAPPING]
result = default+options
except IOError as err:
log.error(
'Could not load mapping file from {}'
.format(mapping_file_path)
)
raise
except ValueError as err:
log.error(
'Could not convert mapping file from json. \nMapping file: {}'
.format(mapping_file_path)
)
raise
return result
def odsh_load_mdk_sample_dataset():
'''
......
......@@ -348,6 +348,8 @@ class OdshPlugin(plugins.SingletonPlugin, DefaultTranslation, DefaultDatasetForm
'get_resource_size': helpers_odsh.get_resource_size,
'get_address_org':helpers_odsh.get_address_org,
'get_body_mail':helpers_odsh.get_body_mail,
'odsh_load_applicable_legislations': helpers_odsh.odsh_load_applicable_legislations,
'odsh_load_hvd_categories': helpers_odsh.odsh_load_hvd_categories,
'odsh_load_mdk_sample_dataset': helpers_odsh.odsh_load_mdk_sample_dataset,
'odsh_load_raw_mdk_sample_dataset': helpers_odsh.odsh_load_raw_mdk_sample_dataset,
'format_resource_format': helpers_odsh.format_resource_format,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment