Skip to content
Snippets Groups Projects
Commit c0c8f803 authored by Daniel Neuwirth's avatar Daniel Neuwirth
Browse files

some bugfixes because of resources.pop() and added the config file editor

parent 7f3831af
No related branches found
No related tags found
No related merge requests found
...@@ -72,7 +72,7 @@ ...@@ -72,7 +72,7 @@
<div class="error-body"><h2>Seite nicht gefunden</h2> <div class="error-body"><h2>Seite nicht gefunden</h2>
<h3>Wie finde ich die gesuchten Inhalte im Landesportal?</h3> <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> <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> <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>
......
...@@ -173,6 +173,7 @@ def update_last_resource_if_value_empty(context, resource, key, value): ...@@ -173,6 +173,7 @@ def update_last_resource_if_value_empty(context, resource, key, value):
package_id = resource.get('package_id') package_id = resource.get('package_id')
package = toolkit.get_action('package_show')(context, {'id': package_id}) package = toolkit.get_action('package_show')(context, {'id': package_id})
resources = package.get('resources') resources = package.get('resources')
if len(resources) > 0:
last_resource = resources.pop() last_resource = resources.pop()
if not last_resource.get(key): if not last_resource.get(key):
last_resource.update({key: value}) last_resource.update({key: value})
......
...@@ -202,6 +202,7 @@ class OdshPlugin(plugins.SingletonPlugin, DefaultTranslation, DefaultDatasetForm ...@@ -202,6 +202,7 @@ class OdshPlugin(plugins.SingletonPlugin, DefaultTranslation, DefaultDatasetForm
def after_create(self, context, resource): def after_create(self, context, resource):
if resource.get('package_id'): if resource.get('package_id'):
tools.save_hash_into_resource(context, resource) tools.save_hash_into_resource(context, resource)
tools.update_files_with_uploaded_files(context, resource)
@staticmethod @staticmethod
def _update_is_new_in_pkg_dict(pkg_dict): def _update_is_new_in_pkg_dict(pkg_dict):
......
...@@ -2,13 +2,21 @@ import os ...@@ -2,13 +2,21 @@ import os
from ckanext.odsh.pdf_to_thumbnail.thumbnail import get_filepath_to_resource, update_last_resource_if_value_empty 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 from ckanext.odsh.lib.uploader import calculate_hash
import ckan.plugins.toolkit as toolkit 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): def save_hash_into_resource(context, resource):
path = get_filepath_to_resource(resource) path = get_filepath_to_resource(resource)
if os.path.exists(path): if os.path.exists(path):
with open(path, 'rb') as file: with open(path, 'rb') as file:
hash = calculate_hash(file) hash = calculate_hash(file)
package = update_last_resource_if_value_empty(context, resource, 'hash', hash) package = update_last_resource_if_value_empty(context, resource, 'hash', hash)
else:
package_id = resource.get('package_id')
package = toolkit.get_action('package_show')(context, {'id': package_id})
resources = package.get('resources') resources = package.get('resources')
last_resource = resources.pop() last_resource = resources.pop()
if last_resource.get(hash) and not last_resource.get('hash_algorithm'): if last_resource.get(hash) and not last_resource.get('hash_algorithm'):
...@@ -16,3 +24,22 @@ def save_hash_into_resource(context, resource): ...@@ -16,3 +24,22 @@ def save_hash_into_resource(context, resource):
resources.append(last_resource) resources.append(last_resource)
package.update({'resources':resources}) package.update({'resources':resources})
toolkit.get_action('package_update')(context, package) 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
...@@ -12,4 +12,5 @@ ...@@ -12,4 +12,5 @@
"http://d-nb.info/gnd/4066490-9":"Wirtschaftspläne", "http://d-nb.info/gnd/4066490-9":"Wirtschaftspläne",
"http://d-nb.info/gnd/4128022-2":"Tätigkeitsbericht", "http://d-nb.info/gnd/4128022-2":"Tätigkeitsbericht",
"http://d-nb.info/gnd/4138783-1":"Gerichtsurteil" "http://d-nb.info/gnd/4138783-1":"Gerichtsurteil"
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment