Skip to content

Commit

Permalink
Merge pull request #161 from GovDataOfficial/extract-read-datasets-to…
Browse files Browse the repository at this point in the history
…-make-it-reusable

Extract read datasets from db to make it re-usable
  • Loading branch information
metaodi authored Jul 30, 2019
2 parents cc814d4 + 4480ddd commit bf510a8
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions ckanext/dcat/harvesters/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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) \
Expand All @@ -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
Expand Down

0 comments on commit bf510a8

Please sign in to comment.