From a29e44703ef677ecaa8fcd14169f99aecd09e077 Mon Sep 17 00:00:00 2001 From: Daniel Neuwirth <daniel.neuwirth@dataport.de> Date: Wed, 30 Oct 2019 07:44:14 +0000 Subject: [PATCH] finished the helper function in thumbnail/helpers --- ckanext/odsh/pdf_to_thumbnail/helpers.py | 20 +++++++++++++++++--- ckanext/odsh/pdf_to_thumbnail/plugin.py | 2 +- ckanext/odsh/templates/package/read.html | 5 +++-- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/ckanext/odsh/pdf_to_thumbnail/helpers.py b/ckanext/odsh/pdf_to_thumbnail/helpers.py index ceb4027c..faddfaa0 100644 --- a/ckanext/odsh/pdf_to_thumbnail/helpers.py +++ b/ckanext/odsh/pdf_to_thumbnail/helpers.py @@ -1,13 +1,27 @@ -from ckan.lib.helpers import resource_display_name +from ckan.lib.helpers import is_url, url_for def thumbnail_namespace(filename): return "/" + filename -def get_name_from_last_pdf_upload(package): +def get_download_link_for_thumbnail(package): resources = package.get('resources') for resource in resources[::-1]: url_type =resource.get('url_type') mimetype = resource.get('mimetype') if url_type == 'upload' and mimetype == 'application/pdf': - return resource_display_name(resource) + package_id = resource.get('package_id') + resource_id = resource.get('id') + pre_resource_url = resource.get('url') + if is_url(pre_resource_url): + url_resource = pre_resource_url + else: + url_resource = url_for(controller='package', + action='resource_download', + id=package_id, + resource_id=resource_id, + filename=pre_resource_url, + qualified = True) + + + return url_resource diff --git a/ckanext/odsh/pdf_to_thumbnail/plugin.py b/ckanext/odsh/pdf_to_thumbnail/plugin.py index 40932363..b3f0a915 100644 --- a/ckanext/odsh/pdf_to_thumbnail/plugin.py +++ b/ckanext/odsh/pdf_to_thumbnail/plugin.py @@ -54,5 +54,5 @@ class ThumbnailPlugin(plugins.SingletonPlugin): return { 'thumbnail_namespace':thumbnail_helpers.thumbnail_namespace, - 'thumbnail_get_name_from_last_pdf_upload':thumbnail_helpers.get_name_from_last_pdf_upload + 'thumbail_get_download_link':thumbnail_helpers.get_download_link_for_thumbnail } diff --git a/ckanext/odsh/templates/package/read.html b/ckanext/odsh/templates/package/read.html index 885c0ce3..c4943693 100644 --- a/ckanext/odsh/templates/package/read.html +++ b/ckanext/odsh/templates/package/read.html @@ -5,7 +5,7 @@ {% set successor_url = h.collection_get_successor(pkg) %} {% set predecessor_url = h.collection_get_predecessor(pkg) %} {% set latest_collection_member = h.collection_get_latest_member(pkg) %} -{% set thumbnail_name = h.thumbnail_get_name_from_last_pdf_upload(pkg) %} +{% set thumbnail_url = h.thumbail_get_download_link(pkg) %} {% block breadcrumb_content %} {% if pkg %} @@ -80,7 +80,8 @@ <section id="dataset-preview"> <h3>{{ _('Preview') }}:</h3> <div class="container-preview-large"> - <a href="#"> + <a href="{{ thumbnail_url }}"> + <img src= "{{ picture }}" alt= "Vorschau"/> </a> </div> -- GitLab