From cb5186962ea3c0f459825f22c5d7c256192650e0 Mon Sep 17 00:00:00 2001 From: amercader Date: Thu, 25 Oct 2018 15:39:57 +0200 Subject: [PATCH 1/2] Support for CKAN 2.9 Use objects from toolkit, remove old checks using missing c properties, Add legacy routes --- ckanext/harvest/helpers.py | 4 +++- ckanext/harvest/plugin.py | 20 ++++++++++++++---- .../harvest/templates/source/admin_base.html | 21 +++++++++---------- .../harvest/templates/source/read_base.html | 13 +++++------- 4 files changed, 34 insertions(+), 24 deletions(-) diff --git a/ckanext/harvest/helpers.py b/ckanext/harvest/helpers.py index c43ecfd77..d00a27ca9 100644 --- a/ckanext/harvest/helpers.py +++ b/ckanext/harvest/helpers.py @@ -1,5 +1,4 @@ -from pylons import request from ckan import logic from ckan import model import ckan.lib.helpers as h @@ -9,6 +8,9 @@ from ckanext.harvest.plugin import DATASET_TYPE_NAME from ckanext.harvest.interfaces import IHarvester +request = p.toolkit.request + + def package_list_for_source(source_id): ''' Creates a dataset list with the ones belonging to a particular harvest diff --git a/ckanext/harvest/plugin.py b/ckanext/harvest/plugin.py index a1971445f..226142257 100644 --- a/ckanext/harvest/plugin.py +++ b/ckanext/harvest/plugin.py @@ -1,6 +1,7 @@ -import types +import json from logging import getLogger +from six import string_types from sqlalchemy.util import OrderedDict from ckan import logic @@ -175,12 +176,11 @@ def edit_template(self): return 'source/edit.html' def setup_template_variables(self, context, data_dict): - - p.toolkit.c.harvest_source = p.toolkit.c.pkg_dict + if hasattr(p.toolkit.c, 'pkg'): + p.toolkit.c.harvest_source = p.toolkit.c.pkg p.toolkit.c.dataset_type = DATASET_TYPE_NAME - def create_package_schema(self): ''' Returns the schema for mapping package data from a form to a format @@ -263,6 +263,18 @@ def update_config(self, config): p.toolkit.add_resource('fanstatic_library', 'ckanext-harvest') p.toolkit.add_resource('public/ckanext/harvest/javascript', 'harvest-extra-field') + if p.toolkit.check_ckan_version(min_version='2.9.0'): + mappings = config.get('ckan.legacy_route_mappings', {}) + if isinstance(mappings, string_types): + mappings = json.loads(mappings) + + mappings.update({ + 'harvest_read': 'harvest.read', + 'harvest_edit': 'harvest.edit', + }) + # https://github.com/ckan/ckan/pull/4521 + config['ckan.legacy_route_mappings'] = json.dumps(mappings) + ## IActions def get_actions(self): diff --git a/ckanext/harvest/templates/source/admin_base.html b/ckanext/harvest/templates/source/admin_base.html index 733428150..e6ebba5f2 100644 --- a/ckanext/harvest/templates/source/admin_base.html +++ b/ckanext/harvest/templates/source/admin_base.html @@ -8,42 +8,41 @@ {% endblock %} {% block action_links %} - {% set show_li = c.__version__.startswith('2.0') %} {% if source.status and source.status.last_job and (source.status.last_job.status == 'New' or source.status.last_job.status == 'Running') %} - {{ '
  • ' if show_li }} Reharvest{{ '
  • ' if show_li }} + Reharvest {% else %} {% set locale = h.dump_json({'content': _('This will re-run the harvesting for this source. Any updates at the source will overwrite the local datasets. Sources with a large number of datasets may take a significant amount of time to finish harvesting. Please confirm you would like us to start reharvesting.')}) %} - {{ '
  • ' if show_li }} + {{ _('Reharvest') }} - {{ '
  • ' if show_li }} + {% endif %} {% if source.status and source.status.last_job and (source.status.last_job.status == 'Running') %} - {{ '
  • ' if show_li }} + {{ _('Stop') }} - {{ '
  • ' if show_li }} + {% endif %} {% set locale = h.dump_json({'content': _('Warning: This will remove all datasets for this source, as well as all previous job reports. Are you sure you want to continue?')}) %} - {{ '
  • ' if show_li }} + {{ _('Clear') }} - {{ '
  • ' if show_li }} - {{ '
  • ' if show_li }} + + {{ _('View harvest source') }} - - {{ '
  • ' if show_li }} + + {% endblock %} {# CKAN 2.0 #} diff --git a/ckanext/harvest/templates/source/read_base.html b/ckanext/harvest/templates/source/read_base.html index 07ac75274..8f9867745 100644 --- a/ckanext/harvest/templates/source/read_base.html +++ b/ckanext/harvest/templates/source/read_base.html @@ -38,14 +38,11 @@

    {{ c.harvest_source.title }}

    {% block page_header %}