[#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:
joetsoi 2013-10-03 15:51:37 +01:00
parent 9b3199b41b
commit da2fd45e80
3 changed files with 7 additions and 7 deletions

View File

@ -165,7 +165,7 @@ def harvest_object_create(context, data_dict):
obj = HarvestObject(
guid=data.get('guid'),
content=data.get('content'),
job=HarvestJob.get(data['job_id']),
job=data['job_id'],
harvest_source_id=data.get('source_id'),
package_id=data.get('package_id'),
extras=[ HarvestObjectExtra(key=k, value=v)

View File

@ -21,7 +21,7 @@ from ckanext.harvest.logic.validators import (harvest_source_url_validator,
dataset_type_exists,
harvest_source_convert_from_config,
harvest_source_id_exists,
harvest_job_id_exists,
harvest_job_exists,
harvest_object_extras_validator,
)
@ -83,7 +83,7 @@ def harvest_object_create_schema():
'guid': [ignore_missing, unicode],
'content': [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],
'package_id': [ignore_missing, package_id_exists],
'extras': [ignore_missing, harvest_object_extras_validator],

View File

@ -22,13 +22,13 @@ def harvest_source_id_exists(value, context):
raise Invalid('Harvest Source with id %r does not exist.' % str(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)
if not result:
raise Invalid('Harvest Job with id %r does not exist.' % str(value))
return value
return result
def _normalize_url(url):
o = urlparse.urlparse(url)