diff --git a/ckanext/harvest/controllers/view.py b/ckanext/harvest/controllers/view.py index b01e04b..659727d 100644 --- a/ckanext/harvest/controllers/view.py +++ b/ckanext/harvest/controllers/view.py @@ -17,6 +17,7 @@ import ckan.lib.helpers as h, json from ckan.lib.base import BaseController, c, \ request, response, render, abort, redirect +from ckanext.harvest.logic import HarvestJobExists, HarvestSourceInactiveError from ckanext.harvest.plugin import DATASET_TYPE_NAME import logging @@ -62,13 +63,14 @@ class ViewController(BaseController): abort(404,_('Harvest source not found')) except p.toolkit.NotAuthorized: abort(401,self.not_auth_message) + except HarvestSourceInactiveError, e: + h.flash_error(_('Cannot create new harvest jobs on inactive ' + 'sources. First, please change the source status ' + 'to \'active\'.')) + except HarvestJobExists, e: + h.flash_notice(_('A harvest job has already been scheduled for ' + 'this source')) except Exception, e: - if 'Can not create jobs on inactive sources' in str(e): - h.flash_error(_('Cannot create new harvest jobs on inactive sources.' - + ' First, please change the source status to \'active\'.')) - elif 'There already is an unrun job for this source' in str(e): - h.flash_notice(_('A harvest job has already been scheduled for this source')) - else: msg = 'An error occurred: [%s]' % str(e) h.flash_error(msg) diff --git a/ckanext/harvest/logic/__init__.py b/ckanext/harvest/logic/__init__.py index 98f60c8..4c00db2 100644 --- a/ckanext/harvest/logic/__init__.py +++ b/ckanext/harvest/logic/__init__.py @@ -8,3 +8,7 @@ except ImportError: class HarvestJobExists(Exception): pass + + +class HarvestSourceInactiveError(Exception): + pass diff --git a/ckanext/harvest/logic/action/create.py b/ckanext/harvest/logic/action/create.py index 472d8f6..f560858 100644 --- a/ckanext/harvest/logic/action/create.py +++ b/ckanext/harvest/logic/action/create.py @@ -4,7 +4,7 @@ import ckan from ckan.plugins import toolkit -from ckanext.harvest.logic import HarvestJobExists +from ckanext.harvest.logic import HarvestJobExists, HarvestSourceInactiveError from ckanext.harvest.plugin import DATASET_TYPE_NAME from ckanext.harvest.model import (HarvestSource, HarvestJob, HarvestObject, HarvestObjectExtra) @@ -97,7 +97,7 @@ def harvest_job_create(context, data_dict): if not source.active: log.warn('Harvest job cannot be created for inactive source %s', source_id) - raise Exception('Can not create jobs on inactive sources') + raise HarvestSourceInactiveError('Can not create jobs on inactive sources') # Check if there already is an unrun or currently running job for this # source