[#65] make harvest_job_exists validator return model object
return the model in the validator instead of checking that it exists in the validator, returning the id and then fetching it again in the action function
This commit is contained in:
parent
9b3199b41b
commit
da2fd45e80
|
@ -165,7 +165,7 @@ def harvest_object_create(context, data_dict):
|
||||||
obj = HarvestObject(
|
obj = HarvestObject(
|
||||||
guid=data.get('guid'),
|
guid=data.get('guid'),
|
||||||
content=data.get('content'),
|
content=data.get('content'),
|
||||||
job=HarvestJob.get(data['job_id']),
|
job=data['job_id'],
|
||||||
harvest_source_id=data.get('source_id'),
|
harvest_source_id=data.get('source_id'),
|
||||||
package_id=data.get('package_id'),
|
package_id=data.get('package_id'),
|
||||||
extras=[ HarvestObjectExtra(key=k, value=v)
|
extras=[ HarvestObjectExtra(key=k, value=v)
|
||||||
|
|
|
@ -21,7 +21,7 @@ from ckanext.harvest.logic.validators import (harvest_source_url_validator,
|
||||||
dataset_type_exists,
|
dataset_type_exists,
|
||||||
harvest_source_convert_from_config,
|
harvest_source_convert_from_config,
|
||||||
harvest_source_id_exists,
|
harvest_source_id_exists,
|
||||||
harvest_job_id_exists,
|
harvest_job_exists,
|
||||||
harvest_object_extras_validator,
|
harvest_object_extras_validator,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -83,7 +83,7 @@ def harvest_object_create_schema():
|
||||||
'guid': [ignore_missing, unicode],
|
'guid': [ignore_missing, unicode],
|
||||||
'content': [ignore_missing, unicode],
|
'content': [ignore_missing, unicode],
|
||||||
'state': [ignore_missing, unicode],
|
'state': [ignore_missing, unicode],
|
||||||
'job_id': [harvest_job_id_exists],
|
'job_id': [harvest_job_exists],
|
||||||
'source_id': [ignore_missing, harvest_source_id_exists],
|
'source_id': [ignore_missing, harvest_source_id_exists],
|
||||||
'package_id': [ignore_missing, package_id_exists],
|
'package_id': [ignore_missing, package_id_exists],
|
||||||
'extras': [ignore_missing, harvest_object_extras_validator],
|
'extras': [ignore_missing, harvest_object_extras_validator],
|
||||||
|
|
|
@ -22,13 +22,13 @@ def harvest_source_id_exists(value, context):
|
||||||
raise Invalid('Harvest Source with id %r does not exist.' % str(value))
|
raise Invalid('Harvest Source with id %r does not exist.' % str(value))
|
||||||
return value
|
return value
|
||||||
|
|
||||||
def harvest_job_id_exists(value, context):
|
def harvest_job_exists(value, context):
|
||||||
|
"""Check if a harvest job exists and returns the model if it does"""
|
||||||
result = HarvestJob.get(value, None)
|
result = HarvestJob.get(value, None)
|
||||||
|
|
||||||
if not result:
|
if not result:
|
||||||
raise Invalid('Harvest Job with id %r does not exist.' % str(value))
|
raise Invalid('Harvest Job with id %r does not exist.' % str(value))
|
||||||
return value
|
return result
|
||||||
|
|
||||||
def _normalize_url(url):
|
def _normalize_url(url):
|
||||||
o = urlparse.urlparse(url)
|
o = urlparse.urlparse(url)
|
||||||
|
|
Loading…
Reference in New Issue