From 9a1294d5c3d26b8f8247f29bfe65d5cba83d129b Mon Sep 17 00:00:00 2001 From: anonymous <anonymous> Date: Mon, 1 Jul 2019 10:32:30 +0200 Subject: [PATCH] uses issued as reference for label NEW --- ckanext/odsh/plugin.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/ckanext/odsh/plugin.py b/ckanext/odsh/plugin.py index 7531b568..13346985 100644 --- a/ckanext/odsh/plugin.py +++ b/ckanext/odsh/plugin.py @@ -561,10 +561,22 @@ class OdshPlugin(plugins.SingletonPlugin, DefaultTranslation, DefaultDatasetForm return pkg_dict def _is_package_new(self, pkg_dict): - date_package_created = self._get_date_from_string(pkg_dict['metadata_created']) - is_new = odsh_helpers.is_within_last_month(date_package_created) + date_package_created_as_str = self._get_date_of_package_creation_from_pkg_dict(pkg_dict) + if date_package_created_as_str == None: + is_new = False + else: + date_package_created = self._get_date_from_string(date_package_created_as_str) + is_new = odsh_helpers.is_within_last_month(date_package_created) return is_new + def _get_date_of_package_creation_from_pkg_dict(self, pkg_dict): + if 'extras' in pkg_dict: + extras = pk_dict['extras'] + issued = odsh_helpers.odsh_extract_value_from_extras(extras=extras, key='issued') # is None if issued not in extras + return issued + else: + return None + def _get_date_from_string(self, date_time_str): # todo: update this function if used in different context date_time_format = '%Y-%m-%dT%H:%M:%S.%f' #e.g. u'2019-06-12T11:56:25.059563' -- GitLab