[#5] Preliminary job report logic function and page (WIP)
This commit is contained in:
parent
234f9f4cc0
commit
30d58b2b7b
|
@ -323,6 +323,47 @@ class ViewController(BaseController):
|
|||
msg = 'An error occurred: [%s]' % str(e)
|
||||
abort(500,msg)
|
||||
|
||||
def show_job_report(self, id, source_dict=False, is_last=False):
|
||||
|
||||
try:
|
||||
context = {'model':model, 'user':c.user}
|
||||
c.job = get_action('harvest_job_show')(context, {'id': id})
|
||||
c.job_report = get_action('harvest_job_report')(context, {'id': id})
|
||||
|
||||
if not source_dict:
|
||||
source_dict = get_action('harvest_source_show')(context, {'id': c.job['source_id']})
|
||||
|
||||
c.harvest_source = source_dict
|
||||
c.is_last_job = is_last
|
||||
|
||||
return render('job/report.html')
|
||||
|
||||
except NotFound:
|
||||
abort(404,_('Harvest job not found'))
|
||||
except NotAuthorized,e:
|
||||
abort(401,self.not_auth_message)
|
||||
except Exception, e:
|
||||
msg = 'An error occurred: [%s]' % str(e)
|
||||
abort(500,msg)
|
||||
|
||||
def show_last_job_report(self, source):
|
||||
|
||||
try:
|
||||
context = {'model':model, 'user':c.user}
|
||||
source_dict = get_action('harvest_source_show')(context, {'id': source})
|
||||
|
||||
return self.show_job_report(source_dict['status']['last_job']['id'],
|
||||
source_dict=source_dict,
|
||||
is_last=True)
|
||||
|
||||
except NotFound:
|
||||
abort(404,_('Harvest source not found'))
|
||||
except NotAuthorized,e:
|
||||
abort(401,self.not_auth_message)
|
||||
except Exception, e:
|
||||
msg = 'An error occurred: [%s]' % str(e)
|
||||
abort(500,msg)
|
||||
|
||||
def _make_autoform_items(self, harvesters_info):
|
||||
states = [{'text': 'active', 'value': 'True'},
|
||||
{'text': 'withdrawn', 'value': 'False'},]
|
||||
|
|
|
@ -150,6 +150,33 @@ def harvest_job_show(context,data_dict):
|
|||
|
||||
return harvest_job_dictize(job,context)
|
||||
|
||||
def harvest_job_report(context, data_dict):
|
||||
|
||||
check_access('harvest_job_show', context, data_dict)
|
||||
|
||||
model = context['model']
|
||||
id = data_dict.get('id')
|
||||
|
||||
job = HarvestJob.get(id)
|
||||
if not job:
|
||||
raise NotFound
|
||||
|
||||
q = model.Session.query(harvest_model.HarvestObjectError) \
|
||||
.join(harvest_model.HarvestObject) \
|
||||
.filter(harvest_model.HarvestObject.harvest_job_id==job.id) \
|
||||
.order_by(harvest_model.HarvestObjectError.harvest_object_id)
|
||||
|
||||
errors= {}
|
||||
for error in q.all():
|
||||
if not error.harvest_object_id in errors:
|
||||
errors[error.harvest_object_id] = []
|
||||
errors[error.harvest_object_id].append({
|
||||
'message': error.message,
|
||||
'line': error.line,
|
||||
'type': error.stage
|
||||
})
|
||||
|
||||
return {'errors': errors}
|
||||
|
||||
def harvest_job_list(context,data_dict):
|
||||
|
||||
|
|
|
@ -219,6 +219,9 @@ class Harvest(p.SingletonPlugin, DefaultDatasetForm):
|
|||
map.connect('harvest_job_show_last', '/' + DATASET_TYPE_NAME + '/{source}/job/last', controller=controller, action='show_last_job')
|
||||
map.connect('harvest_job_show', '/' + DATASET_TYPE_NAME + '/{source}/job/{id}', controller=controller, action='show_job')
|
||||
|
||||
map.connect('harvest_job_report_last', '/' + DATASET_TYPE_NAME + '/{source}/job/last/report', controller=controller, action='show_last_job_report')
|
||||
map.connect('harvest_job_report', '/' + DATASET_TYPE_NAME + '/{source}/job/{id}/report', controller=controller, action='show_job_report')
|
||||
|
||||
return map
|
||||
|
||||
def update_config(self, config):
|
||||
|
|
|
@ -0,0 +1,56 @@
|
|||
{% extends "page.html" %}
|
||||
|
||||
{% block subtitle %}{{ _('Harvest Job Report')}}{% endblock %}
|
||||
|
||||
{% block breadcrumb_content %}
|
||||
<li>{{ h.nav_named_link(_('Harvest Sources'), '{0}_search'.format(c.dataset_type)) }}</li>
|
||||
<li>{{ h.nav_named_link(c.harvest_source.title|truncate(30), '{0}_read'.format(c.dataset_type), id=c.harvest_source.name) }}</li>
|
||||
<li>{{ _('Jobs') }}</li>
|
||||
{% if c.is_last_job %}
|
||||
<li class="active">{{ h.nav_link(_('Last'), controller='ckanext.harvest.controllers.view:ViewController', action='show_last_job', source=c.harvest_source.name)}}</li>
|
||||
{% else %}
|
||||
<li class="active">{{ h.nav_link(c.job.id|truncate(30), controller='ckanext.harvest.controllers.view:ViewController', action='show_job', id=c.job.id, source=c.harvest_source.name)}}</li>
|
||||
{% endif %}
|
||||
|
||||
{% endblock %}
|
||||
|
||||
{% block primary %}
|
||||
|
||||
<article class="module">
|
||||
<div class="module-content">
|
||||
<h1 class="page-heading">{{ _('Report') }}</h1>
|
||||
|
||||
<div style='font-size: 1.5em; margin: 1em 0;'>
|
||||
{% set stats = c.job.stats %}
|
||||
{% for action in ['added', 'updated', 'deleted', 'errored'] %}
|
||||
{% if action in stats and stats[action] > 0 %}
|
||||
<span>{{ stats[action] }} {{ _(action) }}</span>
|
||||
{% else %}
|
||||
<span>0 {{ _(action) }}</span>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
</div>
|
||||
|
||||
|
||||
<div style='font-size: 1.5em; margin: 1em 0;'>
|
||||
{{ c.job_report.errors.keys()|length}} documents with errors
|
||||
</div>
|
||||
|
||||
{% for harvest_object_id in c.job_report.errors.keys() %}
|
||||
<div>
|
||||
<div>{{ harvest_object_id }}</div>
|
||||
{% for error in c.job_report.errors[harvest_object_id] %}
|
||||
<div style="margin-left: 2em">{{ error.message }}
|
||||
{% if error.line %}
|
||||
<span>(line {{error.line}})</span>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
|
||||
{% endfor %}
|
||||
|
||||
</div>
|
||||
</article>
|
||||
{% endblock %}
|
||||
|
Loading…
Reference in New Issue