[forms] Adapt CLI commands to changes in lib

This commit is contained in:
Adrià Mercader 2011-05-13 16:00:36 +01:00
parent bbe459527f
commit b3a88070e3
2 changed files with 55 additions and 49 deletions

View File

@ -128,23 +128,29 @@ class Harvester(CkanCommand):
publisher_id = unicode(self.args[5]) publisher_id = unicode(self.args[5])
else: else:
publisher_id = u'' publisher_id = u''
try:
source = create_harvest_source({
'url':url,
'type':type,
'active':active,
'user_id':user_id,
'publisher_id':publisher_id})
source = create_harvest_source({ print 'Created new harvest source:'
'url':url, self.print_harvest_source(source)
'type':type,
'active':active,
'user_id':user_id,
'publisher_id':publisher_id})
print 'Created new harvest source:' sources = get_harvest_sources()
self.print_harvest_source(source) self.print_there_are('harvest source', sources)
sources = get_harvest_sources() # Create a Harvest Job for the new Source
self.print_there_are('harvest source', sources) create_harvest_job(source['id'])
print 'A new Harvest Job for this source has also been created'
except ValidationError,e:
print 'An error occurred:'
print str(e.error_dict)
raise e
# Create a Harvest Job for the new Source
create_harvest_job(source['id'])
print 'A new Harvest Job for this source has also been created'
def remove_harvest_source(self): def remove_harvest_source(self):
if len(self.args) >= 2: if len(self.args) >= 2:

View File

@ -240,6 +240,8 @@ def edit_harvest_source(source_id,data_dict):
schema = harvest_source_form_schema() schema = harvest_source_form_schema()
source = HarvestSource.get(source_id) source = HarvestSource.get(source_id)
if not source:
raise NotFound('Harvest source %s does not exist' % source_id)
# Add source id to the dict, as some validators will need it # Add source id to the dict, as some validators will need it
data_dict["id"] = source.id data_dict["id"] = source.id
@ -260,10 +262,10 @@ def edit_harvest_source(source_id,data_dict):
def remove_harvest_source(source_id): def remove_harvest_source(source_id):
try:
source = HarvestSource.get(source_id) source = HarvestSource.get(source_id)
except: if not source:
raise Exception('Source %s does not exist' % source_id) raise NotFound('Harvest source %s does not exist' % source_id)
# Don't actually delete the record, just flag it as inactive # Don't actually delete the record, just flag it as inactive
source.active = False source.active = False
@ -291,11 +293,9 @@ def get_harvest_jobs(**kwds):
def create_harvest_job(source_id): def create_harvest_job(source_id):
# Check if source exists # Check if source exists
try: source = HarvestSource.get(source_id)
#We'll need the actual HarvestSource if not source:
source = HarvestSource.get(source_id) raise NotFound('Harvest source %s does not exist' % source_id)
except:
raise Exception('Source %s does not exist' % source_id)
# Check if the source is active # Check if the source is active
if not source.active: if not source.active:
@ -344,10 +344,10 @@ def get_harvest_objects(**kwds):
def import_last_objects(source_id=None): def import_last_objects(source_id=None):
if source_id: if source_id:
try: source = HarvestSource.get(source_id)
source = HarvestSource.get(source_id) if not source:
except: raise NotFound('Harvest source %s does not exist' % source_id)
raise Exception('Source %s does not exist' % source_id)
last_objects = Session.query(HarvestObject) \ last_objects = Session.query(HarvestObject) \
.join(HarvestJob) \ .join(HarvestJob) \
.filter(HarvestJob.source==source) \ .filter(HarvestJob.source==source) \