diff --git a/ckanext/harvest/controllers/view.py b/ckanext/harvest/controllers/view.py index bb02da2..ed8098c 100644 --- a/ckanext/harvest/controllers/view.py +++ b/ckanext/harvest/controllers/view.py @@ -43,7 +43,6 @@ class ViewController(BaseController): # Request all harvest sources c.sources = get_harvest_sources() - #TODO: show source reports return render('ckanext/harvest/index.html') def create(self): @@ -58,31 +57,37 @@ class ViewController(BaseController): except urllib2.HTTPError as e: msg = 'An error occurred: [%s %s]' % (str(e.getcode()),e.msg) h.flash_error(msg) - return render('ckanext/harvest/create.html') if request.method == 'POST': # Build an object like the one expected by the DGU form API data = { 'form_data': {'HarvestSource--url': request.POST['HarvestSource--url'], - 'HarvestSource--description': request.POST['HarvestSource--description']}, - 'user_ref':'', - 'publisher_ref':'' + 'HarvestSource--description': request.POST['HarvestSource--description'], + 'HarvestSource--type': request.POST['HarvestSource--type'], + }, + 'user_id':'', + 'publisher_id':'' } data = json.dumps(data) try: - r = self._do_request(form_url,data) + rq = self._do_request(form_url,data) 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 if e.getcode() == 500: msg = msg + ' Does the source already exist?' - h.flash_error(msg) - finally: - redirect(h.url_for(controller='harvest', action='index')) + elif e.getcode() == 400: + c.form = e.read() + c.mode = 'create' + return render('ckanext/harvest/create.html') + else: + h.flash_error(msg) + redirect(h.url_for(controller='harvest', action='index')) def show(self,id): try: @@ -117,20 +122,27 @@ class ViewController(BaseController): data = { 'form_data': {'HarvestSource-%s-url' % id: request.POST['HarvestSource-%s-url' % id] , + 'HarvestSource-%s-type' % id: request.POST['HarvestSource-%s-type' % id], 'HarvestSource-%s-description' % id: request.POST['HarvestSource-%s-description' % id]}, - 'user_ref':'', - 'publisher_ref':'' + 'user_id':'', + 'publisher_id':'' } data = json.dumps(data) try: r = self._do_request(form_url,data) h.flash_success('Harvesting source edited successfully') - except urllib2.HTTPError as e: - msg = 'An error occurred: [%s %s]' % (str(e.getcode()),e.msg) - h.flash_error(msg) - finally: + redirect(h.url_for(controller='harvest', action='index', id=None)) + except urllib2.HTTPError as e: + if e.getcode() == 400: + c.form = e.read() + c.mode = 'edit' + return render('ckanext/harvest/create.html') + else: + msg = 'An error occurred: [%s %s]' % (str(e.getcode()),e.msg) + h.flash_error(msg) + redirect(h.url_for(controller='harvest', action='index',id=None)) def create_harvesting_job(self,id): try: diff --git a/templates/ckanext/harvest/create.html b/templates/ckanext/harvest/create.html index d3e2e3b..374be13 100644 --- a/templates/ckanext/harvest/create.html +++ b/templates/ckanext/harvest/create.html @@ -17,13 +17,11 @@
-

${title}

${Markup(c.form)}
-
diff --git a/templates/ckanext/harvest/index.html b/templates/ckanext/harvest/index.html index 23c01bd..52ffb5a 100644 --- a/templates/ckanext/harvest/index.html +++ b/templates/ckanext/harvest/index.html @@ -37,8 +37,17 @@ ${source.url} ${source.type} ${source.active} - ${source.status.overall_statistics.added} pkgs ${source.status.overall_statistics.errors} errors - ${source.status.next_harvest} + + + ${source.status.msg} + ${source.status.msg} + + + ${source.status.overall_statistics.added} pkgs ${source.status.overall_statistics.errors} errors + ${source.status.next_harvest} + + + ${source.created}