From 8576ad6784918e363a0619310aa9ae5d7528837e Mon Sep 17 00:00:00 2001 From: amercader Date: Mon, 4 Feb 2013 18:20:58 +0000 Subject: [PATCH] [#5] Add job listing page --- ckanext/harvest/controllers/view.py | 18 +++++++ ckanext/harvest/logic/action/get.py | 2 + ckanext/harvest/plugin.py | 1 + ckanext/harvest/templates_new/job/list.html | 56 +++++++++++++++++++++ ckanext/harvest/templates_new/job/read.html | 4 +- 5 files changed, 79 insertions(+), 2 deletions(-) create mode 100644 ckanext/harvest/templates_new/job/list.html diff --git a/ckanext/harvest/controllers/view.py b/ckanext/harvest/controllers/view.py index 3892884..5ac4bd8 100644 --- a/ckanext/harvest/controllers/view.py +++ b/ckanext/harvest/controllers/view.py @@ -334,6 +334,24 @@ class ViewController(BaseController): is_last=True) + def list_jobs(self, source): + + try: + context = {'model':model, 'user':c.user} + c.harvest_source = get_action('harvest_source_show')(context, {'id': source}) + c.jobs = get_action('harvest_job_list')(context, {'source_id': c.harvest_source['id']}) + + return render('job/list.html') + + 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 ea012e9..4177507 100644 --- a/ckanext/harvest/logic/action/get.py +++ b/ckanext/harvest/logic/action/get.py @@ -212,6 +212,8 @@ def harvest_job_list(context,data_dict): if status: query = query.filter(HarvestJob.status==status) + query = query.order_by(HarvestJob.created.desc()) + jobs = query.all() return [harvest_job_dictize(job,context) for job in jobs] diff --git a/ckanext/harvest/plugin.py b/ckanext/harvest/plugin.py index 754ce2c..ac5dd05 100644 --- a/ckanext/harvest/plugin.py +++ b/ckanext/harvest/plugin.py @@ -216,6 +216,7 @@ class Harvest(p.SingletonPlugin, DefaultDatasetForm): map.connect('harvest_object_show', '/harvest/object/:id', controller=controller, action='show_object') + map.connect('harvest_job_list', '/' + DATASET_TYPE_NAME + '/{source}/job', controller=controller, action='list_jobs') 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') diff --git a/ckanext/harvest/templates_new/job/list.html b/ckanext/harvest/templates_new/job/list.html new file mode 100644 index 0000000..6e86f46 --- /dev/null +++ b/ckanext/harvest/templates_new/job/list.html @@ -0,0 +1,56 @@ +{% extends "page.html" %} + +{% block subtitle %}{{ _('Harvest Jobs')}}{% endblock %} + +{% block breadcrumb_content %} +
  • {{ h.nav_named_link(_('Harvest Sources'), '{0}_search'.format(c.dataset_type)) }}
  • +
  • {{ h.nav_named_link(c.harvest_source.title|truncate(30), '{0}_read'.format(c.dataset_type), id=c.harvest_source.name) }}
  • +
  • {{ h.nav_link(_('Jobs'), controller='ckanext.harvest.controllers.view:ViewController', action='list_jobs', source=c.harvest_source.name)}}
  • +{% endblock %} + +{% block primary %} + +
    +
    +

    {{ _('Harvest Jobs') }}

    + + {% if c.jobs|length == 0 %} +

    {{ _('No jobs yet for this source') }}

    + {% else %} + + + + + + + + + + + + + + + {% for job in c.jobs %} + + + + + {% for action in ['added', 'updated', 'deleted', 'errored'] %} + {% if action in stats and stats[action] > 0 %} + + {% else %} + + {% endif %} + {% endfor %} + + + {% endfor %} + +
    {{ _('Created') }}{{ _('Finished') }}{{ _('Status') }}{{ _('Added') }}{{ _('Updated') }}{{ _('Deleted') }}{{ _('Errors') }}{{ _('Full report') }}
    {{ h.render_datetime(job.gather_started, with_hours=True) }}{{ h.render_datetime(job.finished, with_hours=True) }}{{ _(job.status) }}{{ stats[action] }}0{{ _('view') }}
    + {% endif %} +
    + +
    +{% endblock %} + diff --git a/ckanext/harvest/templates_new/job/read.html b/ckanext/harvest/templates_new/job/read.html index 49a6b00..c98b25a 100644 --- a/ckanext/harvest/templates_new/job/read.html +++ b/ckanext/harvest/templates_new/job/read.html @@ -1,11 +1,11 @@ {% extends "page.html" %} -{% block subtitle %}{{ _('Harvest Job Summary')}}{% endblock %} +{% block subtitle %}{{ _('Harvest Job Report')}}{% endblock %} {% block breadcrumb_content %}
  • {{ h.nav_named_link(_('Harvest Sources'), '{0}_search'.format(c.dataset_type)) }}
  • {{ h.nav_named_link(c.harvest_source.title|truncate(30), '{0}_read'.format(c.dataset_type), id=c.harvest_source.name) }}
  • -
  • {{ _('Jobs') }}
  • +
  • {{ h.nav_link(_('Jobs'), controller='ckanext.harvest.controllers.view:ViewController', action='list_jobs', source=c.harvest_source.name)}}
  • {% if c.is_last_job %}
  • {{ h.nav_link(_('Last'), controller='ckanext.harvest.controllers.view:ViewController', action='show_last_job', source=c.harvest_source.name)}}
  • {% else %}