From 7820d1dc0e5474434b68ee33075b254ff1dd0eca Mon Sep 17 00:00:00 2001 From: Jin-Sun-tts Date: Wed, 24 Jan 2024 11:34:11 -0500 Subject: [PATCH] added exception for parent dataset absent in collection --- ckanext/geodatagov/helpers.py | 8 ++++++-- ckanext/geodatagov/templates/package/read.html | 13 +++++++++---- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/ckanext/geodatagov/helpers.py b/ckanext/geodatagov/helpers.py index 1a1892d0..5ab56f81 100644 --- a/ckanext/geodatagov/helpers.py +++ b/ckanext/geodatagov/helpers.py @@ -3,6 +3,7 @@ from ckan import plugins as p from ckanext.harvest.model import HarvestSource +from ckan.logic import NotFound, NotAuthorized log = logging.getLogger(__name__) @@ -59,8 +60,11 @@ def get_harvest_source_config(harvester_id): def get_collection_package(collection_package_id): - package = p.toolkit.get_action('package_show')({}, {'id': collection_package_id}) - return package + try: + package = p.toolkit.get_action('package_show')({}, {'id': collection_package_id}) + return package + except (NotFound, NotAuthorized): + pass def string(value): diff --git a/ckanext/geodatagov/templates/package/read.html b/ckanext/geodatagov/templates/package/read.html index 3ebea9bb..c606fadb 100644 --- a/ckanext/geodatagov/templates/package/read.html +++ b/ckanext/geodatagov/templates/package/read.html @@ -14,10 +14,15 @@

{{ _('Collection') }}

{% set collection_package = h.get_collection_package(collection_package_id) %}

{{ _('Collection') }}

-

{{ _('This dataset is part of the following collection:') }}

- + {% if collection_package %} +

{{ _('This dataset is part of the following collection:') }}

+ + {% else %} +

{{ _('This dataset is part of the a collection.') }}

+

{{ _('Search other datasets within the same collection') }}

+ {% endif %}
{% endif %} {% endblock %}