[refactoring] Update view controller and templates
This commit is contained in:
parent
aaf7885f43
commit
312e9b8209
|
@ -43,7 +43,6 @@ class ViewController(BaseController):
|
||||||
# Request all harvest sources
|
# Request all harvest sources
|
||||||
c.sources = get_harvest_sources()
|
c.sources = get_harvest_sources()
|
||||||
|
|
||||||
#TODO: show source reports
|
|
||||||
return render('ckanext/harvest/index.html')
|
return render('ckanext/harvest/index.html')
|
||||||
|
|
||||||
def create(self):
|
def create(self):
|
||||||
|
@ -58,30 +57,36 @@ class ViewController(BaseController):
|
||||||
except urllib2.HTTPError as e:
|
except urllib2.HTTPError as e:
|
||||||
msg = 'An error occurred: [%s %s]' % (str(e.getcode()),e.msg)
|
msg = 'An error occurred: [%s %s]' % (str(e.getcode()),e.msg)
|
||||||
h.flash_error(msg)
|
h.flash_error(msg)
|
||||||
|
|
||||||
return render('ckanext/harvest/create.html')
|
return render('ckanext/harvest/create.html')
|
||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
# Build an object like the one expected by the DGU form API
|
# Build an object like the one expected by the DGU form API
|
||||||
data = {
|
data = {
|
||||||
'form_data':
|
'form_data':
|
||||||
{'HarvestSource--url': request.POST['HarvestSource--url'],
|
{'HarvestSource--url': request.POST['HarvestSource--url'],
|
||||||
'HarvestSource--description': request.POST['HarvestSource--description']},
|
'HarvestSource--description': request.POST['HarvestSource--description'],
|
||||||
'user_ref':'',
|
'HarvestSource--type': request.POST['HarvestSource--type'],
|
||||||
'publisher_ref':''
|
},
|
||||||
|
'user_id':'',
|
||||||
|
'publisher_id':''
|
||||||
}
|
}
|
||||||
data = json.dumps(data)
|
data = json.dumps(data)
|
||||||
try:
|
try:
|
||||||
r = self._do_request(form_url,data)
|
rq = 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:
|
except urllib2.HTTPError as e:
|
||||||
msg = 'An error occurred: [%s %s]' % (str(e.getcode()),e.msg)
|
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
|
# The form API returns just a 500, so we are not exactly sure of what
|
||||||
# happened, but most probably it was a duplicate entry
|
# happened, but most probably it was a duplicate entry
|
||||||
if e.getcode() == 500:
|
if e.getcode() == 500:
|
||||||
msg = msg + ' Does the source already exist?'
|
msg = msg + ' Does the source already exist?'
|
||||||
|
elif e.getcode() == 400:
|
||||||
|
c.form = e.read()
|
||||||
|
c.mode = 'create'
|
||||||
|
return render('ckanext/harvest/create.html')
|
||||||
|
else:
|
||||||
h.flash_error(msg)
|
h.flash_error(msg)
|
||||||
finally:
|
|
||||||
redirect(h.url_for(controller='harvest', action='index'))
|
redirect(h.url_for(controller='harvest', action='index'))
|
||||||
|
|
||||||
def show(self,id):
|
def show(self,id):
|
||||||
|
@ -117,19 +122,26 @@ class ViewController(BaseController):
|
||||||
data = {
|
data = {
|
||||||
'form_data':
|
'form_data':
|
||||||
{'HarvestSource-%s-url' % id: request.POST['HarvestSource-%s-url' % id] ,
|
{'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]},
|
'HarvestSource-%s-description' % id: request.POST['HarvestSource-%s-description' % id]},
|
||||||
'user_ref':'',
|
'user_id':'',
|
||||||
'publisher_ref':''
|
'publisher_id':''
|
||||||
}
|
}
|
||||||
data = json.dumps(data)
|
data = json.dumps(data)
|
||||||
try:
|
try:
|
||||||
r = self._do_request(form_url,data)
|
r = self._do_request(form_url,data)
|
||||||
|
|
||||||
h.flash_success('Harvesting source edited successfully')
|
h.flash_success('Harvesting source edited successfully')
|
||||||
|
|
||||||
|
redirect(h.url_for(controller='harvest', action='index', id=None))
|
||||||
except urllib2.HTTPError as e:
|
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)
|
msg = 'An error occurred: [%s %s]' % (str(e.getcode()),e.msg)
|
||||||
h.flash_error(msg)
|
h.flash_error(msg)
|
||||||
finally:
|
|
||||||
redirect(h.url_for(controller='harvest', action='index',id=None))
|
redirect(h.url_for(controller='harvest', action='index',id=None))
|
||||||
|
|
||||||
def create_harvesting_job(self,id):
|
def create_harvesting_job(self,id):
|
||||||
|
|
|
@ -17,13 +17,11 @@
|
||||||
|
|
||||||
<div py:match="content">
|
<div py:match="content">
|
||||||
<div class="harvest-content">
|
<div class="harvest-content">
|
||||||
<py:if test="c.sources">
|
|
||||||
<h1>${title}</h1>
|
<h1>${title}</h1>
|
||||||
<form action="${c.mode}" method="POST">
|
<form action="${c.mode}" method="POST">
|
||||||
${Markup(c.form)}
|
${Markup(c.form)}
|
||||||
<input id="save" name="save" value="Save" type="submit" />
|
<input id="save" name="save" value="Save" type="submit" />
|
||||||
</form>
|
</form>
|
||||||
</py:if>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<xi:include href="../../layout.html" />
|
<xi:include href="../../layout.html" />
|
||||||
|
|
|
@ -37,8 +37,17 @@
|
||||||
<td>${source.url}</td>
|
<td>${source.url}</td>
|
||||||
<td>${source.type}</td>
|
<td>${source.type}</td>
|
||||||
<td>${source.active}</td>
|
<td>${source.active}</td>
|
||||||
|
<py:choose>
|
||||||
|
<py:when test="'msg' in source.status">
|
||||||
|
<td>${source.status.msg}</td>
|
||||||
|
<td>${source.status.msg}</td>
|
||||||
|
</py:when>
|
||||||
|
<py:otherwise>
|
||||||
<td>${source.status.overall_statistics.added} pkgs ${source.status.overall_statistics.errors} errors</td>
|
<td>${source.status.overall_statistics.added} pkgs ${source.status.overall_statistics.errors} errors</td>
|
||||||
<td>${source.status.next_harvest}</td>
|
<td>${source.status.next_harvest}</td>
|
||||||
|
</py:otherwise>
|
||||||
|
</py:choose>
|
||||||
|
|
||||||
<td>${source.created}</td>
|
<td>${source.created}</td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
|
|
Loading…
Reference in New Issue