diff --git a/ckanext/harvest/controllers/view.py b/ckanext/harvest/controllers/view.py index babae96..b7660cf 100644 --- a/ckanext/harvest/controllers/view.py +++ b/ckanext/harvest/controllers/view.py @@ -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'},] diff --git a/ckanext/harvest/logic/action/get.py b/ckanext/harvest/logic/action/get.py index a499ecf..b7de909 100644 --- a/ckanext/harvest/logic/action/get.py +++ b/ckanext/harvest/logic/action/get.py @@ -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): diff --git a/ckanext/harvest/plugin.py b/ckanext/harvest/plugin.py index aff3437..bc087a3 100644 --- a/ckanext/harvest/plugin.py +++ b/ckanext/harvest/plugin.py @@ -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): diff --git a/ckanext/harvest/templates_new/job/report.html b/ckanext/harvest/templates_new/job/report.html new file mode 100644 index 0000000..d18a831 --- /dev/null +++ b/ckanext/harvest/templates_new/job/report.html @@ -0,0 +1,56 @@ +{% extends "page.html" %} + +{% block subtitle %}{{ _('Harvest Job Report')}}{% endblock %} + +{% block breadcrumb_content %} +