diff --git a/ckanext/odsh/helper_pkg_dict.py b/ckanext/odsh/helper_pkg_dict.py index 26f7917c6ef77f4368c9f8581fc411fee48e0e57..514e3551360ac26151653f12f77739a000b6dca7 100644 --- a/ckanext/odsh/helper_pkg_dict.py +++ b/ckanext/odsh/helper_pkg_dict.py @@ -3,7 +3,6 @@ import re import ckanext.odsh.helpers as helpers_odsh import datetime -import ckanext.odsh.helpers_tpsh as helpers_tpsh import ckanext.odsh.collection.helpers as helpers_collection import ckanext.odsh.uri_store as uri_store @@ -48,7 +47,7 @@ class HelperPgkDict(object): uris_collection_members = self.get_uris_collection_members() ckan_ids_collection_members = [self.get_id_from_store(uri) for uri in uris_collection_members] for id_pkg in ckan_ids_collection_members: - helpers_tpsh.add_pkg_to_collection(id_pkg, id_collection) + helpers_odsh.add_pkg_to_collection(id_pkg, id_collection) log.info('Added package with id {} to collection with id {}'.format(id_pkg, id_collection)) def get_uris_collection_members(self): @@ -80,7 +79,7 @@ class HelperPgkDict(object): id_pkg = self.pkg_dict.get('id') uri_collection = self.get_collection_uri() id_collection = uri_store.get_id_from_uri(uri_collection) - helpers_tpsh.add_pkg_to_collection(id_pkg, id_collection) + helpers_odsh.add_pkg_to_collection(id_pkg, id_collection) log.info('Added package with id {} to collection with id {}'.format(id_pkg, id_collection)) diff --git a/ckanext/odsh/helpers.py b/ckanext/odsh/helpers.py index 980a3460ebf6613a382a8d7e7cd1044e7605ff78..d4f79562cda126cbb9714a7f66f4630a6b05fabb 100644 --- a/ckanext/odsh/helpers.py +++ b/ckanext/odsh/helpers.py @@ -26,6 +26,10 @@ import ckan.lib.helpers as helpers import os.path from collections import OrderedDict import pkg_resources +import ckan.logic.action.create as create + + +CKAN_TYPES = {'http://dcat-ap.de/def/datasetTypes/collection': 'collection'} get_action = logic.get_action log = logging.getLogger(__name__) @@ -535,3 +539,185 @@ def odsh_load_raw_mdk_sample_dataset(): ) raise return result + + +def map_dct_type_to_ckan_type(dct_type): + ''' + matches the field dct:type from a harvested rdf file + to the corresponding ckan package type + ''' + ckan_type = CKAN_TYPES.get(dct_type) + return ckan_type + +def map_ckan_type_to_dct_type(ckan_type): + DCT_TYPES = _revert_dict(CKAN_TYPES) + dct_type = DCT_TYPES.get(ckan_type) + return dct_type + +def _revert_dict(d): + d_inverse = {v: k for k, v in d.items()} + return d_inverse + +def add_pkg_to_collection(id_pkg, id_collection): + if id_pkg and id_collection: + relationship_dict = { + 'subject': id_pkg, + 'object': id_collection, + 'type': 'child_of', + } + toolkit.get_action('package_relationship_create')(None, relationship_dict) + +def correct_missing_relationship(pkg_dict, pkg_relationships_from_model): + ''' + This function corrects missing relationship in show package. + Note this fix is only good with one or non relationship. + This error is well known but was not fixed. https://github.com/ckan/ckan/issues/3114 + The error causes the deletation of relationships, because package_show is + used in resource_create to get the package. + ''' + if pkg_relationships_from_model: + relationship_from_model = pkg_relationships_from_model[0] + relationship_list_from_dict = pkg_dict.get('relationships_as_subject') + type_pkg = pkg_dict.get('type') + needs_update = type_pkg == 'dataset' and not relationship_list_from_dict + if needs_update: + relationship_for_package = { + '__extras': { + 'object_package_id': relationship_from_model.object_package_id, + 'subject_package_id': relationship_from_model.subject_package_id, + }, + 'comment': relationship_from_model.subject_package_id, + 'id': relationship_from_model.id, + 'type': relationship_from_model.type, + } + pkg_dict['relationships_as_subject'].append(relationship_for_package) + return pkg_dict + +def get_pkg_relationships_from_model(pkg_dict): + pkg_id = pkg_dict.get('id') + return model.Package.get(pkg_id).get_relationships() + +def load_language_mapping(): + extension_path = pkg_resources.resource_filename('ckanext.odsh', '') + file_path = config.get('ckanext.odsh.language_mapping', extension_path + '/resources/language_mapping.json') + with open(file_path) as language_mapping_json: + LANGUAGE_MAPPING = json.loads(language_mapping_json.read()) + return LANGUAGE_MAPPING + +def load_json_to_ordered_dict(json_str): + return json.loads(json_str, object_pairs_hook=OrderedDict) + +def get_language_of_package(pkg_dict): + LANGUAGE_MAPPING = load_language_mapping() + language_id = _get_language_id(pkg_dict) + if not language_id: + return None + language = LANGUAGE_MAPPING.get(language_id) + return language + +def get_language_icon(pkg_dict): + ICONS = { + "http://publications.europa.eu/resource/authority/language/DAN": '/base/images/icon_lang_danish.png', + "http://publications.europa.eu/resource/authority/language/ENG": '/base/images/icon_lang_english.png', + } + language_id = _get_language_id(pkg_dict) + if not language_id: + return None + return ICONS.get(language_id) + +def _get_language_id(pkg_dict): + language_id = odsh_extract_value_from_extras(pkg_dict.get('extras'), 'language') + language_id = pkg_dict.get('language') + if not language_id: + language_id = odsh_extract_value_from_extras( + pkg_dict.get('extras'), 'language' + ) + if not language_id: + return None + language_id_cleaned = re.sub('[\[\]\"]', '', language_id) + return language_id_cleaned + +def get_spatial_for_selection(): + extension_path = pkg_resources.resource_filename('ckanext.odsh', '') + file_path = config.get('ckanext.odsh.spatial.mapping', extension_path + '/resources/schleswig-holstein_geojson.csv') + with open(file_path, newline='') as mapping_file: + cr = csv.reader(mapping_file, delimiter="\t") + spatial_mapping = list(cr) + + unique_mapping = [] + seen_values = set() + for key, value, _ in spatial_mapping: + if value in seen_values: + continue # Skip if the value has already been seen + + if "municipalityKey" in key: + unique_mapping.append({'key': key, 'value': value}) + else: + # Check if there is a municipality key entry for the value + municipality_entry = next( + (entry for entry in spatial_mapping if entry[1] == value and "municipalityKey" in entry[0]), + None + ) + + if municipality_entry: + # If a municipality key entry exists, use it instead of the current key + unique_mapping.append({'key': municipality_entry[0], 'value': value}) + else: + # Otherwise, use the current key + unique_mapping.append({'key': key, 'value': value}) + + seen_values.add(value) + + unique_mapping.append({'key': '', 'value': ''}) + return unique_mapping + + +def get_language_for_selection(): + LANGUAGE_MAPPING = load_language_mapping() + dict_for_select_box = [{'key': key, 'value': LANGUAGE_MAPPING[key]} for key in LANGUAGE_MAPPING] + return dict_for_select_box + +def get_package_dict(name): + ''' + raises ckan.logic.NotFound if not found + ''' + package_dict = toolkit.get_action('package_show')(None, {'id': name}) + return package_dict + +def size_of_fmt(num, suffix='B'): + for unit in ['',' k',' M',' G',' T',' P',' E',' Z']: + if abs(num) < 1000.0: + return "%3.1f%s%s" % (num, unit, suffix) + num /= 1000.0 + return "%.1f%s%s" % (num, 'Y', suffix) + +def get_resource_size(resource): + resource_size = resource.get('size') + if resource_size: + return size_of_fmt(resource_size) + + +def get_address_org(organization): + list_extras = organization.get('extras') + address = dict() + if not list_extras: + return address + for extra in list_extras: + address.update({extra.get('key'):extra.get('value')}) + web = address.get('web') + if web and not web.startswith('http'): + web = 'http://' + web + address.update({'web':web}) + return address + + +def get_body_mail(organization, package): + package_name = package.get('name') + url = helpers.url_for('dataset.read', id=package_name, qualified = True) + title = package.get('title') + anrede = "Sehr geehrte Damen und Herren," + "%0D%0A" + "%0D%0A" + "zu folgendem Eintrag habe ich eine Anmerkung/Frage:" + "%0D%0A" + "%0D%0A" + mail_titel = "Titel: " + title + "%0D%0A" + mail_document = "Dokument-ID: " + package_name + "%0D%0A" + mail_url = "URL: " + url + "%0D%0A" + "%0D%0A" + message = mail_titel + mail_document + mail_url + "Mein Kommentar:" + "%0D%0A" + "%0D%0A" + "%0D%0A" + "%0D%0A" + return anrede + message diff --git a/ckanext/odsh/helpers_tpsh.py b/ckanext/odsh/helpers_tpsh.py deleted file mode 100644 index e0142ea6d6bf8fc542de5f542dbb9c462b821b08..0000000000000000000000000000000000000000 --- a/ckanext/odsh/helpers_tpsh.py +++ /dev/null @@ -1,207 +0,0 @@ -# encoding: utf-8 - -import csv -import datetime -import logging -import json -import re -import urllib.request, urllib.error, urllib.parse -from collections import OrderedDict -import subprocess -import os -import pkg_resources - -from ckan.common import config -import ckan.lib.helpers as helpers -import ckan.logic.action.create as create -import ckan.model as model -import ckan.plugins.toolkit as toolkit - - -import ckanext.odsh.helpers as odsh_helpers - -log = logging.getLogger(__name__) - -CKAN_TYPES = {'http://dcat-ap.de/def/datasetTypes/collection': 'collection'} - - -def map_dct_type_to_ckan_type(dct_type): - ''' - matches the field dct:type from a harvested rdf file - to the corresponding ckan package type - ''' - ckan_type = CKAN_TYPES.get(dct_type) - return ckan_type - -def map_ckan_type_to_dct_type(ckan_type): - DCT_TYPES = _revert_dict(CKAN_TYPES) - dct_type = DCT_TYPES.get(ckan_type) - return dct_type - -def _revert_dict(d): - d_inverse = {v: k for k, v in d.items()} - return d_inverse - -def add_pkg_to_collection(id_pkg, id_collection): - if id_pkg and id_collection: - relationship_dict = { - 'subject': id_pkg, - 'object': id_collection, - 'type': 'child_of', - } - toolkit.get_action('package_relationship_create')(None, relationship_dict) - -def correct_missing_relationship(pkg_dict, pkg_relationships_from_model): - ''' - This function corrects missing relationship in show package. - Note this fix is only good with one or non relationship. - This error is well known but was not fixed. https://github.com/ckan/ckan/issues/3114 - The error causes the deletation of relationships, because package_show is - used in resource_create to get the package. - ''' - if pkg_relationships_from_model: - relationship_from_model = pkg_relationships_from_model[0] - relationship_list_from_dict = pkg_dict.get('relationships_as_subject') - type_pkg = pkg_dict.get('type') - needs_update = type_pkg == 'dataset' and not relationship_list_from_dict - if needs_update: - relationship_for_package = { - '__extras': { - 'object_package_id': relationship_from_model.object_package_id, - 'subject_package_id': relationship_from_model.subject_package_id, - }, - 'comment': relationship_from_model.subject_package_id, - 'id': relationship_from_model.id, - 'type': relationship_from_model.type, - } - pkg_dict['relationships_as_subject'].append(relationship_for_package) - return pkg_dict - -def get_pkg_relationships_from_model(pkg_dict): - pkg_id = pkg_dict.get('id') - return model.Package.get(pkg_id).get_relationships() - -def load_language_mapping(): - extension_path = pkg_resources.resource_filename('ckanext.odsh', '') - file_path = config.get('ckanext.odsh.language_mapping', extension_path + '/resources/language_mapping.json') - with open(file_path) as language_mapping_json: - LANGUAGE_MAPPING = json.loads(language_mapping_json.read()) - return LANGUAGE_MAPPING - -def load_json_to_ordered_dict(json_str): - return json.loads(json_str, object_pairs_hook=OrderedDict) - -def get_language_of_package(pkg_dict): - LANGUAGE_MAPPING = load_language_mapping() - language_id = _get_language_id(pkg_dict) - if not language_id: - return None - language = LANGUAGE_MAPPING.get(language_id) - return language - -def get_language_icon(pkg_dict): - ICONS = { - "http://publications.europa.eu/resource/authority/language/DAN": '/base/images/icon_lang_danish.png', - "http://publications.europa.eu/resource/authority/language/ENG": '/base/images/icon_lang_english.png', - } - language_id = _get_language_id(pkg_dict) - if not language_id: - return None - return ICONS.get(language_id) - -def _get_language_id(pkg_dict): - language_id = odsh_helpers.odsh_extract_value_from_extras(pkg_dict.get('extras'), 'language') - language_id = pkg_dict.get('language') - if not language_id: - language_id = odsh_helpers.odsh_extract_value_from_extras( - pkg_dict.get('extras'), 'language' - ) - if not language_id: - return None - language_id_cleaned = re.sub('[\[\]\"]', '', language_id) - return language_id_cleaned - -def get_spatial_for_selection(): - extension_path = pkg_resources.resource_filename('ckanext.odsh', '') - file_path = config.get('ckanext.odsh.spatial.mapping', extension_path + '/resources/schleswig-holstein_geojson.csv') - with open(file_path, newline='') as mapping_file: - cr = csv.reader(mapping_file, delimiter="\t") - spatial_mapping = list(cr) - - unique_mapping = [] - seen_values = set() - for key, value, _ in spatial_mapping: - if value in seen_values: - continue # Skip if the value has already been seen - - if "municipalityKey" in key: - unique_mapping.append({'key': key, 'value': value}) - else: - # Check if there is a municipality key entry for the value - municipality_entry = next( - (entry for entry in spatial_mapping if entry[1] == value and "municipalityKey" in entry[0]), - None - ) - - if municipality_entry: - # If a municipality key entry exists, use it instead of the current key - unique_mapping.append({'key': municipality_entry[0], 'value': value}) - else: - # Otherwise, use the current key - unique_mapping.append({'key': key, 'value': value}) - - seen_values.add(value) - - unique_mapping.append({'key': '', 'value': ''}) - return unique_mapping - - -def get_language_for_selection(): - LANGUAGE_MAPPING = load_language_mapping() - dict_for_select_box = [{'key': key, 'value': LANGUAGE_MAPPING[key]} for key in LANGUAGE_MAPPING] - return dict_for_select_box - -def get_package_dict(name): - ''' - raises ckan.logic.NotFound if not found - ''' - package_dict = toolkit.get_action('package_show')(None, {'id': name}) - return package_dict - -def size_of_fmt(num, suffix='B'): - for unit in ['',' k',' M',' G',' T',' P',' E',' Z']: - if abs(num) < 1000.0: - return "%3.1f%s%s" % (num, unit, suffix) - num /= 1000.0 - return "%.1f%s%s" % (num, 'Y', suffix) - -def get_resource_size(resource): - resource_size = resource.get('size') - if resource_size: - return size_of_fmt(resource_size) - - -def get_address_org(organization): - list_extras = organization.get('extras') - address = dict() - if not list_extras: - return address - for extra in list_extras: - address.update({extra.get('key'):extra.get('value')}) - web = address.get('web') - if web and not web.startswith('http'): - web = 'http://' + web - address.update({'web':web}) - return address - - -def get_body_mail(organization, package): - package_name = package.get('name') - url = helpers.url_for('dataset.read', id=package_name, qualified = True) - title = package.get('title') - anrede = "Sehr geehrte Damen und Herren," + "%0D%0A" + "%0D%0A" + "zu folgendem Eintrag habe ich eine Anmerkung/Frage:" + "%0D%0A" + "%0D%0A" - mail_titel = "Titel: " + title + "%0D%0A" - mail_document = "Dokument-ID: " + package_name + "%0D%0A" - mail_url = "URL: " + url + "%0D%0A" + "%0D%0A" - message = mail_titel + mail_document + mail_url + "Mein Kommentar:" + "%0D%0A" + "%0D%0A" + "%0D%0A" + "%0D%0A" - return anrede + message diff --git a/ckanext/odsh/logic/action.py b/ckanext/odsh/logic/action.py index 071397e85858da96f3946dbe0cb364ad967311eb..36d6b9782d7ad496fef3eeea5d53fedfeabbf00e 100644 --- a/ckanext/odsh/logic/action.py +++ b/ckanext/odsh/logic/action.py @@ -17,7 +17,7 @@ log = logging.getLogger(__name__) from ckanext.odsh.setup_proxy import setup_proxy, clear_proxy from ckanext.odsh.collection.helpers import get_collection_id, get_package_dict -from ckanext.odsh.helpers_tpsh import add_pkg_to_collection +from ckanext.odsh.helpers import add_pkg_to_collection from ckanext.odsh.helpers import odsh_extract_value_from_extras diff --git a/ckanext/odsh/plugin.py b/ckanext/odsh/plugin.py index a7ffbfa4c5a0d2e1a8bd5cf01b6cb7a479778ac4..c6d2cce365c1e0f42426c10b6dee0fce5455d043 100644 --- a/ckanext/odsh/plugin.py +++ b/ckanext/odsh/plugin.py @@ -11,8 +11,7 @@ import ckan.plugins as plugins import ckan.plugins.toolkit as toolkit # imports from this extension -import ckanext.odsh.helpers as odsh_helpers -import ckanext.odsh.helpers_tpsh as helpers_tpsh +import ckanext.odsh.helpers as helpers_odsh import ckanext.odsh.helper_pkg_dict as helper_pkg_dict from .helper_pkg_dict import HelperPgkDict import ckanext.odsh.logic.action as action @@ -60,7 +59,7 @@ class OdshPlugin(plugins.SingletonPlugin, DefaultTranslation, DefaultDatasetForm # DCAT # if toolkit.asbool(toolkit.config.get('ckanext.dcat.enable_rdf_endpoints', True)): - # odsh_helpers.odsh_remove_route(map, 'dcat_catalog') + # helpers_odsh.odsh_remove_route(map, 'dcat_catalog') # bp_default.add_url_rule('/catalog.<any("xml", "rdf", "n3", "ttl", "jsonld"):_format>', view_func=dcat_view.read_catalog, defaults={'_format': 'xml'}, methods=['GET']) # Package @@ -248,9 +247,9 @@ class OdshPlugin(plugins.SingletonPlugin, DefaultTranslation, DefaultDatasetForm adds the following key-value-pairs to pkg_dict: # key: 'is_new', value: True if the dataset has been created within the last month ''' - pkg_dict = helpers_tpsh.correct_missing_relationship( + pkg_dict = helpers_odsh.correct_missing_relationship( pkg_dict, - helpers_tpsh.get_pkg_relationships_from_model(pkg_dict) + helpers_odsh.get_pkg_relationships_from_model(pkg_dict) ) self._update_is_new_in_pkg_dict(pkg_dict) @@ -298,39 +297,39 @@ class OdshPlugin(plugins.SingletonPlugin, DefaultTranslation, DefaultDatasetForm # extension they belong to, to avoid clashing with functions from # other extensions. return { - 'odsh_main_groups': odsh_helpers.odsh_main_groups, - 'odsh_now': odsh_helpers.odsh_now, - 'odsh_group_id_selected': odsh_helpers.odsh_group_id_selected, - 'odsh_get_facet_items_dict': odsh_helpers.odsh_get_facet_items_dict, - 'odsh_openness_score_dataset_html': odsh_helpers.odsh_openness_score_dataset_html, - 'odsh_get_resource_details': odsh_helpers.odsh_get_resource_details, - 'odsh_get_resource_views': odsh_helpers.odsh_get_resource_views, - 'odsh_get_bounding_box': odsh_helpers.odsh_get_bounding_box, - 'odsh_get_spatial_text': odsh_helpers.odsh_get_spatial_text, - 'odsh_render_datetime': odsh_helpers.odsh_render_datetime, - 'odsh_resource_formats': odsh_helpers.odsh_resource_formats, - 'odsh_encodeurl': odsh_helpers.odsh_encodeurl, - 'odsh_extract_error': odsh_helpers.odsh_extract_error, - 'odsh_extract_error_new': odsh_helpers.odsh_extract_error_new, - 'odsh_extract_value_from_extras': odsh_helpers.odsh_extract_value_from_extras, - 'odsh_create_checksum': odsh_helpers.odsh_create_checksum, - 'presorted_license_options': odsh_helpers.presorted_license_options, - 'odsh_has_more_facets': odsh_helpers.odsh_has_more_facets, - 'odsh_public_url': odsh_helpers.odsh_public_url, - 'odsh_spatial_extends_available': odsh_helpers.spatial_extends_available, - 'odsh_public_resource_url': odsh_helpers.odsh_public_resource_url, - 'odsh_show_testbanner': odsh_helpers.odsh_show_testbanner, + 'odsh_main_groups': helpers_odsh.odsh_main_groups, + 'odsh_now': helpers_odsh.odsh_now, + 'odsh_group_id_selected': helpers_odsh.odsh_group_id_selected, + 'odsh_get_facet_items_dict': helpers_odsh.odsh_get_facet_items_dict, + 'odsh_openness_score_dataset_html': helpers_odsh.odsh_openness_score_dataset_html, + 'odsh_get_resource_details': helpers_odsh.odsh_get_resource_details, + 'odsh_get_resource_views': helpers_odsh.odsh_get_resource_views, + 'odsh_get_bounding_box': helpers_odsh.odsh_get_bounding_box, + 'odsh_get_spatial_text': helpers_odsh.odsh_get_spatial_text, + 'odsh_render_datetime': helpers_odsh.odsh_render_datetime, + 'odsh_resource_formats': helpers_odsh.odsh_resource_formats, + 'odsh_encodeurl': helpers_odsh.odsh_encodeurl, + 'odsh_extract_error': helpers_odsh.odsh_extract_error, + 'odsh_extract_error_new': helpers_odsh.odsh_extract_error_new, + 'odsh_extract_value_from_extras': helpers_odsh.odsh_extract_value_from_extras, + 'odsh_create_checksum': helpers_odsh.odsh_create_checksum, + 'presorted_license_options': helpers_odsh.presorted_license_options, + 'odsh_has_more_facets': helpers_odsh.odsh_has_more_facets, + 'odsh_public_url': helpers_odsh.odsh_public_url, + 'odsh_spatial_extends_available': helpers_odsh.spatial_extends_available, + 'odsh_public_resource_url': helpers_odsh.odsh_public_resource_url, + 'odsh_show_testbanner': helpers_odsh.odsh_show_testbanner, 'get_daterange_prettified': helper_pkg_dict.get_daterange_prettified, - 'get_language_of_package': helpers_tpsh.get_language_of_package, - 'get_language_icon': helpers_tpsh.get_language_icon, - 'short_name_for_category': odsh_helpers.short_name_for_category, - 'get_spatial_for_selection': helpers_tpsh.get_spatial_for_selection, - 'get_language_for_selection': helpers_tpsh.get_language_for_selection, - 'get_resource_size': helpers_tpsh.get_resource_size, - 'get_address_org':helpers_tpsh.get_address_org, - 'get_body_mail':helpers_tpsh.get_body_mail, - 'odsh_load_mdk_sample_dataset': odsh_helpers.odsh_load_mdk_sample_dataset, - 'odsh_load_raw_mdk_sample_dataset': odsh_helpers.odsh_load_raw_mdk_sample_dataset, + 'get_language_of_package': helpers_odsh.get_language_of_package, + 'get_language_icon': helpers_odsh.get_language_icon, + 'short_name_for_category': helpers_odsh.short_name_for_category, + 'get_spatial_for_selection': helpers_odsh.get_spatial_for_selection, + 'get_language_for_selection': helpers_odsh.get_language_for_selection, + '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_mdk_sample_dataset': helpers_odsh.odsh_load_mdk_sample_dataset, + 'odsh_load_raw_mdk_sample_dataset': helpers_odsh.odsh_load_raw_mdk_sample_dataset, } diff --git a/ckanext/odsh/profiles/odsh_dcat_de_profile.py b/ckanext/odsh/profiles/odsh_dcat_de_profile.py index e5986f812b941a13dca6a1dd3dd0603ef945cac6..7e2026c69a5becb95103e1b4da5d35382f4d26e4 100644 --- a/ckanext/odsh/profiles/odsh_dcat_de_profile.py +++ b/ckanext/odsh/profiles/odsh_dcat_de_profile.py @@ -8,8 +8,7 @@ from ckanext.dcat.utils import resource_uri import ckanext.dcatde.dataset_utils as ds_utils from ckanext.dcatde.profiles import DCATdeProfile, DCATDE, DCAT, DCATDE_1_0, DCATDE_1_0_1 -import ckanext.odsh.helpers as odsh_helpers -import ckanext.odsh.helpers_tpsh as helpers_tpsh +import ckanext.odsh.helpers as helpers_odsh import ckanext.odsh.collection.helpers as helpers_collection @@ -49,7 +48,7 @@ class ODSHDCATdeProfile(DCATdeProfile): def _parse_type(self, dataset_dict, dataset_ref): dct_type = self._object(dataset_ref, DCT.type) if dct_type: - ckan_type = helpers_tpsh.map_dct_type_to_ckan_type(str(dct_type)) + ckan_type = helpers_odsh.map_dct_type_to_ckan_type(str(dct_type)) dataset_dict.update({'type': ckan_type}) def _parse_references(self, dataset_dict, dataset_ref): @@ -114,7 +113,7 @@ class ODSHDCATdeProfile(DCATdeProfile): Adds reference (Musterdatenkatalog/Musterdatensatz) extra field to dcat:references. ''' - sample_dataset_uri = odsh_helpers.odsh_extract_value_from_extras(dataset_dict.get('extras'), 'reference') + sample_dataset_uri = helpers_odsh.odsh_extract_value_from_extras(dataset_dict.get('extras'), 'reference') if sample_dataset_uri: self.g.set( (dataset_ref, DCT.references, @@ -150,7 +149,7 @@ class ODSHDCATdeProfile(DCATdeProfile): dct:type ''' ckan_type = self._get_ckan_type(dataset_dict) - dct_type = helpers_tpsh.map_ckan_type_to_dct_type(ckan_type) + dct_type = helpers_odsh.map_ckan_type_to_dct_type(ckan_type) if dct_type: self.g.set( (dataset_ref, DCT.type, diff --git a/ckanext/odsh/tests/test_helper_pkg_dict.py b/ckanext/odsh/tests/test_helper_pkg_dict.py index 5b892b7baffca6196d6cffc9a49c7299302d7d80..6e5b3267ee2947bae45c3df51589244869cffa08 100644 --- a/ckanext/odsh/tests/test_helper_pkg_dict.py +++ b/ckanext/odsh/tests/test_helper_pkg_dict.py @@ -3,7 +3,7 @@ from mock import patch, call import unittest from ckanext.odsh.helper_pkg_dict import HelperPgkDict -import ckanext.odsh.helpers_tpsh as helpers_tpsh +import ckanext.odsh.helpers as helpers_odsh import ckanext.odsh.uri_store as uri_store class TestHelperPkgDict(unittest.TestCase): @@ -46,7 +46,7 @@ class TestHelperPkgDict(unittest.TestCase): assert not (shall_be_part_of_collection) def test_update_relations_to_collection_members_leads_to_correct_call_of_add_to_collection(self): - with patch.object(helpers_tpsh, 'add_pkg_to_collection') as patch_add_package_to_collection: + with patch.object(helpers_odsh, 'add_pkg_to_collection') as patch_add_package_to_collection: # arange # taken from debugging _update_relations_to_collection_members: dataset_dict_collection = { @@ -72,7 +72,7 @@ class TestHelperPkgDict(unittest.TestCase): uri_store._set_uri_to_id({}) def test_update_relation_to_collection_leads_to_correct_call_of_add_to_collection(self): - with patch.object(helpers_tpsh, 'add_pkg_to_collection') as patch_add_package_to_collection: + with patch.object(helpers_odsh, 'add_pkg_to_collection') as patch_add_package_to_collection: # arange # taken from debugging _update_relations_to_collection_members: dataset_dict_collection_member = { diff --git a/ckanext/odsh/tests/test_helpers_tpsh.py b/ckanext/odsh/tests/test_helpers_tpsh.py index ab7960ae51c77b90a84436ed7d65505b8f7d75f8..3c3f4ca3c30322bcbeffd2b9940d51b84046c3fa 100644 --- a/ckanext/odsh/tests/test_helpers_tpsh.py +++ b/ckanext/odsh/tests/test_helpers_tpsh.py @@ -3,11 +3,11 @@ from collections import namedtuple, OrderedDict from mock import patch from ckan.common import config -from ckanext.odsh.tests_tpsh.resources import org_dicts +from ckanext.odsh.tests.resources import org_dicts import unittest -from ckanext.odsh.helpers_tpsh import ( +from ckanext.odsh.helpers import ( map_dct_type_to_ckan_type, map_ckan_type_to_dct_type, correct_missing_relationship, diff --git a/ckanext/odsh/tests/test_profiles.py b/ckanext/odsh/tests/test_profiles.py index 4a1ac3f62fa941120b63da0cab396e8e22202e6f..acf97611b0f92d80d570be3b955ca0661843cfb2 100644 --- a/ckanext/odsh/tests/test_profiles.py +++ b/ckanext/odsh/tests/test_profiles.py @@ -18,7 +18,7 @@ class TestODSHDCATdeProfileParseDatasetWithCollection(unittest.TestCase): ''' def setUp(self): rdf_graph = Graph() - rdf_graph.parse('ckanext/odsh/tests_tpsh/resources/collection1.rdf') + rdf_graph.parse('ckanext/odsh/tests/resources/collection1.rdf') self.profile = profiles.ODSHDCATdeProfile(rdf_graph) self.dataset_ref_with_collection = URIRefOrLiteral( 'http://opendata.schleswig-holstein.de/dataset/LAsDSH_SER_Statistik_anerkannte_Versorgungsberechtigte' diff --git a/ckanext/odsh/validation.py b/ckanext/odsh/validation.py index e3fa8e24ccd9092fc9d87f7a1e40fe532d72fcf7..d91731555d44d7d927071098ef0179b5ba015e8a 100644 --- a/ckanext/odsh/validation.py +++ b/ckanext/odsh/validation.py @@ -13,7 +13,7 @@ import ckan.plugins.toolkit as toolkit import ckan.model as model from ckan.lib.navl.dictization_functions import Missing -from ckanext.odsh.helpers_tpsh import get_package_dict +from ckanext.odsh.helpers import get_package_dict from ckanext.odsh.helpers import odsh_resource_formats import ckan.plugins.toolkit as tk import pkg_resources