Support for CKAN 2.9
Use objects from toolkit, remove old checks using missing c properties, Add legacy routes
This commit is contained in:
parent
7a22a3cf46
commit
cb5186962e
|
@ -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.model import UPDATE_FREQUENCIES
|
|||
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
|
||||
|
|
|
@ -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 @@ class Harvest(p.SingletonPlugin, DefaultDatasetForm, DefaultTranslation):
|
|||
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 @@ class Harvest(p.SingletonPlugin, DefaultDatasetForm, DefaultTranslation):
|
|||
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):
|
||||
|
|
|
@ -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') %}
|
||||
{{ '<li>' if show_li }}<a class="btn disabled" rel="tooltip" title="There already is an unrun job for this source"><i class="fa fa-lg fa-refresh icon-refresh icon-large"></i> Reharvest</a>{{ '</li>' if show_li }}
|
||||
<a class="btn disabled" rel="tooltip" title="There already is an unrun job for this source"><i class="fa fa-lg fa-refresh icon-refresh icon-large"></i> Reharvest</a>
|
||||
{% 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.')}) %}
|
||||
{{ '<li>' if show_li }}
|
||||
|
||||
<a href="{{ h.url_for('harvest_refresh', id=source.id) }}" class="btn btn-default" data-module="confirm-action" data-module-i18n="{{ locale }}"
|
||||
title="{{ _('Start a new harvesting job for this harvest source now') }}">
|
||||
<i class="fa fa-refresh icon-refresh"></i>
|
||||
{{ _('Reharvest') }}
|
||||
</a>
|
||||
{{ '</li>' if show_li }}
|
||||
|
||||
{% endif %}
|
||||
{% if source.status and source.status.last_job and (source.status.last_job.status == 'Running') %}
|
||||
{{ '<li>' if show_li }}
|
||||
|
||||
<a href="{{ h.url_for('harvest_job_abort', source=source.name, id=source.status.last_job.id) }}" class="btn btn-default" title="Stop this Job">
|
||||
<i class="fa fa-ban icon-ban-circle"></i>
|
||||
{{ _('Stop') }}
|
||||
</a>
|
||||
{{ '</li>' 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?')}) %}
|
||||
{{ '<li>' if show_li }}
|
||||
|
||||
<a href="{{ h.url_for('harvest_clear', id=source.id) }}" class="btn btn-default" data-module="confirm-action" data-module-i18n="{{ locale }}"
|
||||
title="{{ _('Delete all harvest jobs and existing datasets from this source') }}">
|
||||
{{ _('Clear') }}
|
||||
</a>
|
||||
{{ '</li>' if show_li }}
|
||||
|
||||
{{ '<li>' if show_li }}
|
||||
|
||||
|
||||
<a href="{{ h.url_for('{0}_read'.format(c.dataset_type), id=source.id) }}" class="btn btn-default">
|
||||
<i class="fa fa-eye eye-open"></i>
|
||||
{{ _('View harvest source') }}
|
||||
</a>
|
||||
|
||||
{{ '</li>' if show_li }}
|
||||
|
||||
|
||||
{% endblock %}
|
||||
|
||||
{# CKAN 2.0 #}
|
||||
|
|
|
@ -38,14 +38,11 @@
|
|||
<article class="module prose">
|
||||
{% block page_header %}
|
||||
<header class="module-content page-header">
|
||||
{# CKAN 2.1+ #}
|
||||
{% if authorized_user and not c.__version__.startswith('2.0') %}
|
||||
{% block content_action %}
|
||||
<div class="content_action">
|
||||
{{ self.admin_link() }}
|
||||
</div>
|
||||
{% endblock %}
|
||||
{% endif %}
|
||||
{% block content_action %}
|
||||
<div class="content_action">
|
||||
{{ self.admin_link() }}
|
||||
</div>
|
||||
{% endblock %}
|
||||
<ul class="nav nav-tabs">
|
||||
{% block page_header_tabs %}
|
||||
{{ h.build_nav_icon('{0}_read'.format(c.dataset_type), _('Datasets'), id=source.name, icon='sitemap') }}
|
||||
|
|
Loading…
Reference in New Issue