Show error notices for duplicate sources and existing jobs.

This commit is contained in:
Adrià Mercader 2011-03-11 12:35:27 +00:00
parent abfd394f0b
commit 81569c0f2c
1 changed files with 30 additions and 18 deletions

View File

@ -24,9 +24,7 @@ class ViewController(BaseController):
try: try:
return urllib2.urlopen(http_request) return urllib2.urlopen(http_request)
except urllib2.HTTPError as e: except urllib2.HTTPError as e:
raise Exception('The API call returned an error: ' + str(e.getcode()) + \ raise
' ' + e.msg + ' [' + e.url + ']')
def index(self): def index(self):
@ -66,12 +64,24 @@ class ViewController(BaseController):
'publisher_ref':'' 'publisher_ref':''
} }
data = json.dumps(data) data = json.dumps(data)
try:
r = self._do_request(form_url,data) r = self._do_request(form_url,data)
h.flash_success('Harvesting source added successfully') h.flash_success('Harvesting source added successfully')
redirect(h.url_for(controller='harvest', action='index')) except urllib2.HTTPError as e:
msg = 'An error occurred: [%s %s]' % (str(e.getcode()),e.msg)
# The form API returns just a 500, so we are not exactly sure of what
# happened, but most probably it was a duplicate entry
msg = msg + ' Does the source already exist?'
h.flash_error(msg)
finally:
redirect(h.url_for(controller='harvest', action='index'))
def show(self,id):
sources_url = self.api_url + '/harvestsource/%s' % id
doc = self._do_request(sources_url).read()
c.source = json.loads(doc)
def create_harvesting_job(self,id): def create_harvesting_job(self,id):
form_url = self.api_url + '/harvestingjob' form_url = self.api_url + '/harvestingjob'
data = { data = {
@ -79,14 +89,16 @@ class ViewController(BaseController):
'user_ref': '' 'user_ref': ''
} }
data = json.dumps(data) data = json.dumps(data)
r = self._do_request(form_url,data) try:
r = self._do_request(form_url,data)
h.flash_success('Refresh requested, harvesting will take place within 15 minutes.')
redirect(h.url_for(controller='harvest', action='index', id=None))
def show(self,id):
sources_url = self.api_url + '/harvestsource/%s' % id
doc = self._do_request(sources_url).read()
c.source = json.loads(doc)
h.flash_success('Refresh requested, harvesting will take place within 15 minutes.')
except urllib2.HTTPError as e:
msg = 'An error occurred: [%s %s]' % (str(e.getcode()),e.msg)
if e.getcode() == 400:
msg = msg + ' ' + e.read()
h.flash_error(msg)
finally:
redirect(h.url_for(controller='harvest', action='index', id=None))
return render('ckanext/harvest/show.html') return render('ckanext/harvest/show.html')