diff --git a/ckanext/odsh/harvest_templates/source/search.html b/ckanext/odsh/harvest_templates/source/search.html index 699fb0e45de450c5e014710c3791baa302dfe178..6d1cb2d8d9906419d8170e98218e7289707dbf1b 100644 --- a/ckanext/odsh/harvest_templates/source/search.html +++ b/ckanext/odsh/harvest_templates/source/search.html @@ -72,7 +72,7 @@ <div class="error-body"><h2>Seite nicht gefunden</h2> <h3>Wie finde ich die gesuchten Inhalte im Landesportal?</h3> - <p><a class="" href="http://www.schleswig-holstein.de/odpstart" title="Zur Startseite">Zur Startseite des Open-Data-Portals</a></p> + <p><a class="" href="http://www.schleswig-holstein.de/trpstart" title="Zur Startseite">Zur Startseite des Transparenz-Portals</a></p> <h3>Kontakt</h3> <p>Bei Fragen oder Problemen mit dem Open-Data-Portal schicken Sie bitte eine E-Mail an die Adresse opendata@lr.landsh.de oder verwenden das Kontaktformular:</p> diff --git a/ckanext/odsh/pdf_to_thumbnail/thumbnail.py b/ckanext/odsh/pdf_to_thumbnail/thumbnail.py index 904e31704a487149a5814572015efeae85f8060b..f488252c63f2ca6b561f1f2b61a5796898934fe6 100644 --- a/ckanext/odsh/pdf_to_thumbnail/thumbnail.py +++ b/ckanext/odsh/pdf_to_thumbnail/thumbnail.py @@ -173,11 +173,12 @@ def update_last_resource_if_value_empty(context, resource, key, value): package_id = resource.get('package_id') package = toolkit.get_action('package_show')(context, {'id': package_id}) resources = package.get('resources') - last_resource = resources.pop() - if not last_resource.get(key): - last_resource.update({key: value}) - resources.append(last_resource) - package.update({'resources': resources}) + if len(resources) > 0: + last_resource = resources.pop() + if not last_resource.get(key): + last_resource.update({key: value}) + resources.append(last_resource) + package.update({'resources': resources}) return package diff --git a/ckanext/odsh/plugin.py b/ckanext/odsh/plugin.py index 54c7146557584e064bdaa02d4d02f6ad8f17b8cd..3fe483e3f8719b6cf8f25f5b67e68986ec75b2cd 100644 --- a/ckanext/odsh/plugin.py +++ b/ckanext/odsh/plugin.py @@ -202,6 +202,7 @@ class OdshPlugin(plugins.SingletonPlugin, DefaultTranslation, DefaultDatasetForm def after_create(self, context, resource): if resource.get('package_id'): tools.save_hash_into_resource(context, resource) + tools.update_files_with_uploaded_files(context, resource) @staticmethod def _update_is_new_in_pkg_dict(pkg_dict): diff --git a/ckanext/odsh/tools.py b/ckanext/odsh/tools.py index 22b999b38d4a163f536510730a3db3e78910f83c..1831d6a3b5e31ac0e72b99c72b470241d1797664 100644 --- a/ckanext/odsh/tools.py +++ b/ckanext/odsh/tools.py @@ -2,17 +2,44 @@ import os from ckanext.odsh.pdf_to_thumbnail.thumbnail import get_filepath_to_resource, update_last_resource_if_value_empty from ckanext.odsh.lib.uploader import calculate_hash import ckan.plugins.toolkit as toolkit +import ckan.authz as authz +from ckan.common import config +from shutil import copyfile def save_hash_into_resource(context, resource): + path = get_filepath_to_resource(resource) if os.path.exists(path): with open(path, 'rb') as file: hash = calculate_hash(file) package = update_last_resource_if_value_empty(context, resource, 'hash', hash) - resources = package.get('resources') - last_resource = resources.pop() - if last_resource.get(hash) and not last_resource.get('hash_algorithm'): - last_resource.update({'hash_algorithm': 'http://dcat-ap.de/def/hashAlgorithms/md/5'}) - resources.append(last_resource) - package.update({'resources':resources}) - toolkit.get_action('package_update')(context, package) + else: + package_id = resource.get('package_id') + package = toolkit.get_action('package_show')(context, {'id': package_id}) + + resources = package.get('resources') + last_resource = resources.pop() + if last_resource.get(hash) and not last_resource.get('hash_algorithm'): + last_resource.update({'hash_algorithm': 'http://dcat-ap.de/def/hashAlgorithms/md/5'}) + resources.append(last_resource) + package.update({'resources':resources}) + toolkit.get_action('package_update')(context, package) + + +def update_files_with_uploaded_files(context, resource): + package_id = resource.get('package_id') + package = toolkit.get_action('package_show')(context, {'id': package_id}) + package_name = package.get('name') + user = context.get('user') + if authz.is_sysadmin(user) and package_name == "list_of_files_for_tpsh7": + origin_path = get_filepath_to_resource(resource) + if resource.get('name') == "subject_mapping.json": + target_path = config.get('ckanext.odsh.subject_mapping') + if resource.get('name') == "language_mapping.json": + target_path = config.get('ckanext.odsh.language_mapping') + if resource.get('name') == "spatial_mapping.csv": + target_path = config.get('ckanext.odsh.spatial.mapping') + if resource.get('name') == "licenses.json": + target_path = config.get('licenses_group_url') + if os.path.exists(origin_path) and target_path: + copyfile(origin_path, target_path) \ No newline at end of file diff --git a/subject_mapping.json b/subject_mapping.json index 820b1eb3a4c8292a88ac4b4f755d79a2bea398b8..1803e7359a9a5eb4bd98f49296c6648692dc65cc 100644 --- a/subject_mapping.json +++ b/subject_mapping.json @@ -12,4 +12,5 @@ "http://d-nb.info/gnd/4066490-9":"Wirtschaftspläne", "http://d-nb.info/gnd/4128022-2":"Tätigkeitsbericht", "http://d-nb.info/gnd/4138783-1":"Gerichtsurteil" + }