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 logic
|
||||||
from ckan import model
|
from ckan import model
|
||||||
import ckan.lib.helpers as h
|
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.plugin import DATASET_TYPE_NAME
|
||||||
from ckanext.harvest.interfaces import IHarvester
|
from ckanext.harvest.interfaces import IHarvester
|
||||||
|
|
||||||
|
request = p.toolkit.request
|
||||||
|
|
||||||
|
|
||||||
def package_list_for_source(source_id):
|
def package_list_for_source(source_id):
|
||||||
'''
|
'''
|
||||||
Creates a dataset list with the ones belonging to a particular harvest
|
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 logging import getLogger
|
||||||
|
|
||||||
|
from six import string_types
|
||||||
from sqlalchemy.util import OrderedDict
|
from sqlalchemy.util import OrderedDict
|
||||||
|
|
||||||
from ckan import logic
|
from ckan import logic
|
||||||
|
@ -175,12 +176,11 @@ class Harvest(p.SingletonPlugin, DefaultDatasetForm, DefaultTranslation):
|
||||||
return 'source/edit.html'
|
return 'source/edit.html'
|
||||||
|
|
||||||
def setup_template_variables(self, context, data_dict):
|
def setup_template_variables(self, context, data_dict):
|
||||||
|
if hasattr(p.toolkit.c, 'pkg'):
|
||||||
p.toolkit.c.harvest_source = p.toolkit.c.pkg_dict
|
p.toolkit.c.harvest_source = p.toolkit.c.pkg
|
||||||
|
|
||||||
p.toolkit.c.dataset_type = DATASET_TYPE_NAME
|
p.toolkit.c.dataset_type = DATASET_TYPE_NAME
|
||||||
|
|
||||||
|
|
||||||
def create_package_schema(self):
|
def create_package_schema(self):
|
||||||
'''
|
'''
|
||||||
Returns the schema for mapping package data from a form to a format
|
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('fanstatic_library', 'ckanext-harvest')
|
||||||
p.toolkit.add_resource('public/ckanext/harvest/javascript', 'harvest-extra-field')
|
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
|
## IActions
|
||||||
|
|
||||||
def get_actions(self):
|
def get_actions(self):
|
||||||
|
|
|
@ -8,42 +8,41 @@
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block action_links %}
|
{% 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 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 %}
|
{% 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.')}) %}
|
{% 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 }}"
|
<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') }}">
|
title="{{ _('Start a new harvesting job for this harvest source now') }}">
|
||||||
<i class="fa fa-refresh icon-refresh"></i>
|
<i class="fa fa-refresh icon-refresh"></i>
|
||||||
{{ _('Reharvest') }}
|
{{ _('Reharvest') }}
|
||||||
</a>
|
</a>
|
||||||
{{ '</li>' if show_li }}
|
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if source.status and source.status.last_job and (source.status.last_job.status == 'Running') %}
|
{% 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">
|
<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>
|
<i class="fa fa-ban icon-ban-circle"></i>
|
||||||
{{ _('Stop') }}
|
{{ _('Stop') }}
|
||||||
</a>
|
</a>
|
||||||
{{ '</li>' if show_li }}
|
|
||||||
{% endif %}
|
{% 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?')}) %}
|
{% 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 }}"
|
<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') }}">
|
title="{{ _('Delete all harvest jobs and existing datasets from this source') }}">
|
||||||
{{ _('Clear') }}
|
{{ _('Clear') }}
|
||||||
</a>
|
</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">
|
<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>
|
<i class="fa fa-eye eye-open"></i>
|
||||||
{{ _('View harvest source') }}
|
{{ _('View harvest source') }}
|
||||||
</a>
|
</a>
|
||||||
|
|
||||||
{{ '</li>' if show_li }}
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{# CKAN 2.0 #}
|
{# CKAN 2.0 #}
|
||||||
|
|
|
@ -38,14 +38,11 @@
|
||||||
<article class="module prose">
|
<article class="module prose">
|
||||||
{% block page_header %}
|
{% block page_header %}
|
||||||
<header class="module-content page-header">
|
<header class="module-content page-header">
|
||||||
{# CKAN 2.1+ #}
|
|
||||||
{% if authorized_user and not c.__version__.startswith('2.0') %}
|
|
||||||
{% block content_action %}
|
{% block content_action %}
|
||||||
<div class="content_action">
|
<div class="content_action">
|
||||||
{{ self.admin_link() }}
|
{{ self.admin_link() }}
|
||||||
</div>
|
</div>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
{% endif %}
|
|
||||||
<ul class="nav nav-tabs">
|
<ul class="nav nav-tabs">
|
||||||
{% block page_header_tabs %}
|
{% block page_header_tabs %}
|
||||||
{{ h.build_nav_icon('{0}_read'.format(c.dataset_type), _('Datasets'), id=source.name, icon='sitemap') }}
|
{{ h.build_nav_icon('{0}_read'.format(c.dataset_type), _('Datasets'), id=source.name, icon='sitemap') }}
|
||||||
|
|
Loading…
Reference in New Issue