Harvesting jobs creation controller
This commit is contained in:
parent
6cc73aa1f7
commit
4f2a233cf1
|
@ -67,6 +67,11 @@ class Harvest(SingletonPlugin):
|
||||||
conditions=dict(method=['POST']),
|
conditions=dict(method=['POST']),
|
||||||
action='create')
|
action='create')
|
||||||
|
|
||||||
|
map.connect('harvest_create', '/harvest/harvestingjob',
|
||||||
|
controller='ckanext.harvest.controllers.view:ViewController',
|
||||||
|
conditions=dict(method=['POST']),
|
||||||
|
action='create_harvesting_job')
|
||||||
|
|
||||||
map.connect('harvest_show', '/harvest/:id',
|
map.connect('harvest_show', '/harvest/:id',
|
||||||
controller='ckanext.harvest.controllers.view:ViewController',
|
controller='ckanext.harvest.controllers.view:ViewController',
|
||||||
action='show')
|
action='show')
|
||||||
|
|
|
@ -8,6 +8,7 @@ from ckan.lib.base import BaseController, c, g, request, \
|
||||||
class ViewController(BaseController):
|
class ViewController(BaseController):
|
||||||
|
|
||||||
api_url = config.get('ckan.api_url', 'http://localhost:5000').rstrip('/')+'/api/2/rest'
|
api_url = config.get('ckan.api_url', 'http://localhost:5000').rstrip('/')+'/api/2/rest'
|
||||||
|
form_api_url = config.get('ckan.api_url', 'http://localhost:5000').rstrip('/')+'/api/2/form'
|
||||||
api_key = config.get('ckan.harvesting.api_key')
|
api_key = config.get('ckan.harvesting.api_key')
|
||||||
|
|
||||||
def _do_request(self,url,data = None):
|
def _do_request(self,url,data = None):
|
||||||
|
@ -49,8 +50,7 @@ class ViewController(BaseController):
|
||||||
def create(self):
|
def create(self):
|
||||||
|
|
||||||
# This is the DGU form API, so we don't use self.api_url
|
# This is the DGU form API, so we don't use self.api_url
|
||||||
form_url = config.get('ckan.api_url', '/').rstrip('/') + \
|
form_url = self.form_api_url + '/harvestsource/create'
|
||||||
'/api/2/form/harvestsource/create'
|
|
||||||
if request.method == 'GET':
|
if request.method == 'GET':
|
||||||
# Request the fields
|
# Request the fields
|
||||||
c.form = self._do_request(form_url).read()
|
c.form = self._do_request(form_url).read()
|
||||||
|
@ -67,14 +67,20 @@ class ViewController(BaseController):
|
||||||
}
|
}
|
||||||
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'))
|
redirect(h.url_for(controller='harvest', action='index'))
|
||||||
except urllib2.HTTPError as e:
|
|
||||||
raise Exception('The forms API returned an error:' + str(e.getcode()) + ' ' + e.msg )
|
|
||||||
|
|
||||||
|
def create_harvesting_job(self):
|
||||||
|
form_url = self.api_url + '/harvestingjob'
|
||||||
|
data = {
|
||||||
|
'source_id': request.POST['source_id'],
|
||||||
|
'user_ref': ''
|
||||||
|
}
|
||||||
|
data = json.dumps(data)
|
||||||
|
r = self._do_request(form_url,data)
|
||||||
|
return r.read()
|
||||||
|
|
||||||
def show(self,id):
|
def show(self,id):
|
||||||
sources_url = self.api_url + '/harvestsource/%s' % id
|
sources_url = self.api_url + '/harvestsource/%s' % id
|
||||||
|
|
Loading…
Reference in New Issue