Merge branch 'named-exceptions'
This commit is contained in:
commit
52fe7fb21d
|
@ -17,6 +17,7 @@ import ckan.lib.helpers as h, json
|
||||||
from ckan.lib.base import BaseController, c, \
|
from ckan.lib.base import BaseController, c, \
|
||||||
request, response, render, abort, redirect
|
request, response, render, abort, redirect
|
||||||
|
|
||||||
|
from ckanext.harvest.logic import HarvestJobExists, HarvestSourceInactiveError
|
||||||
from ckanext.harvest.plugin import DATASET_TYPE_NAME
|
from ckanext.harvest.plugin import DATASET_TYPE_NAME
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
@ -62,13 +63,14 @@ class ViewController(BaseController):
|
||||||
abort(404,_('Harvest source not found'))
|
abort(404,_('Harvest source not found'))
|
||||||
except p.toolkit.NotAuthorized:
|
except p.toolkit.NotAuthorized:
|
||||||
abort(401,self.not_auth_message)
|
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:
|
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)
|
msg = 'An error occurred: [%s]' % str(e)
|
||||||
h.flash_error(msg)
|
h.flash_error(msg)
|
||||||
|
|
||||||
|
|
|
@ -8,3 +8,7 @@ except ImportError:
|
||||||
|
|
||||||
class HarvestJobExists(Exception):
|
class HarvestJobExists(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class HarvestSourceInactiveError(Exception):
|
||||||
|
pass
|
||||||
|
|
|
@ -4,7 +4,7 @@ import ckan
|
||||||
|
|
||||||
from ckan.plugins import toolkit
|
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.plugin import DATASET_TYPE_NAME
|
||||||
from ckanext.harvest.model import (HarvestSource, HarvestJob, HarvestObject,
|
from ckanext.harvest.model import (HarvestSource, HarvestJob, HarvestObject,
|
||||||
HarvestObjectExtra)
|
HarvestObjectExtra)
|
||||||
|
@ -97,7 +97,7 @@ def harvest_job_create(context, data_dict):
|
||||||
if not source.active:
|
if not source.active:
|
||||||
log.warn('Harvest job cannot be created for inactive source %s',
|
log.warn('Harvest job cannot be created for inactive source %s',
|
||||||
source_id)
|
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
|
# Check if there already is an unrun or currently running job for this
|
||||||
# source
|
# source
|
||||||
|
|
Loading…
Reference in New Issue