From 4480ddd87aeb92b368d1ed64cc867fd72e207600 Mon Sep 17 00:00:00 2001 From: seitenbau-govdata Date: Mon, 29 Jul 2019 16:03:42 +0200 Subject: [PATCH] Extract read datasets from db to make it re-usable --- ckanext/dcat/harvesters/base.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/ckanext/dcat/harvesters/base.py b/ckanext/dcat/harvesters/base.py index 289a8302..a33a4127 100644 --- a/ckanext/dcat/harvesters/base.py +++ b/ckanext/dcat/harvesters/base.py @@ -149,11 +149,9 @@ def get_original_url(self, harvest_object_id): return obj.source.url return None - def _get_existing_dataset(self, guid): + def _read_datasets_from_db(self, guid): ''' - Checks if a dataset with a certain guid extra already exists - - Returns a dict as the ones returned by package_show + Returns a database result of datasets matching the given guid. ''' datasets = model.Session.query(model.Package.id) \ @@ -162,6 +160,16 @@ def _get_existing_dataset(self, guid): .filter(model.PackageExtra.value == guid) \ .filter(model.Package.state == 'active') \ .all() + return datasets + + def _get_existing_dataset(self, guid): + ''' + Checks if a dataset with a certain guid extra already exists + + Returns a dict as the ones returned by package_show + ''' + + datasets = self._read_datasets_from_db(guid) if not datasets: return None