diff --git a/ckanext/harvest/controllers/view.py b/ckanext/harvest/controllers/view.py index e34cf13..3a41a08 100644 --- a/ckanext/harvest/controllers/view.py +++ b/ckanext/harvest/controllers/view.py @@ -8,7 +8,7 @@ from ckan import model import ckan.plugins as p import ckan.lib.helpers as h, json from ckan.lib.base import BaseController, c, \ - response, render, abort, redirect + request, response, render, abort, redirect from ckanext.harvest.plugin import DATASET_TYPE_NAME @@ -28,9 +28,15 @@ class ViewController(BaseController): def delete(self,id): try: context = {'model':model, 'user':c.user} + + context['clear_source'] = request.params.get('clear', '').lower() in (u'true', u'1') + p.toolkit.get_action('harvest_source_delete')(context, {'id':id}) - h.flash_success(_('Harvesting source successfully inactivated')) + if context['clear_source']: + h.flash_success(_('Harvesting source successfully cleared')) + else: + h.flash_success(_('Harvesting source successfully inactivated')) redirect(h.url_for('{0}_admin'.format(DATASET_TYPE_NAME), id=id)) except p.toolkit.ObjectNotFound: diff --git a/ckanext/harvest/logic/action/delete.py b/ckanext/harvest/logic/action/delete.py index dd13e24..405aa3a 100644 --- a/ckanext/harvest/logic/action/delete.py +++ b/ckanext/harvest/logic/action/delete.py @@ -25,3 +25,10 @@ def harvest_source_delete(context, data_dict): p.toolkit.check_access('harvest_source_delete', context, data_dict) p.toolkit.get_action('package_delete')(context, data_dict) + + if context.get('clear_source', False): + + # We need the id, the name won't work + package_dict = p.toolkit.get_action('package_show')(context, data_dict) + + p.toolkit.get_action('harvest_source_clear')(context, {'id': package_dict['id']}) diff --git a/ckanext/harvest/templates_new/source/new_source_form.html b/ckanext/harvest/templates_new/source/new_source_form.html index 145c2d6..8f79c34 100644 --- a/ckanext/harvest/templates_new/source/new_source_form.html +++ b/ckanext/harvest/templates_new/source/new_source_form.html @@ -85,12 +85,30 @@

{% block delete_button %} {% if data.get('id', None) and h.check_access('harvest_source_delete', {'id': data.id}) and not data.get('state', 'none') == 'deleted' %} - {% set locale = h.dump_json({'content': _('Are you sure you want to delete this harvest source?')}) %} - {% block delete_button_text %}{{ _('Delete') }}{% endblock %} + {% set locale_delete = h.dump_json({'content': _('This will flag the source as deleted but keep all its datasets and previous jobs. Are you sure you want to delete this harvest source?')}) %} + {% set locale_clear = h.dump_json({'content': _('Warning: Apart from deleting this source, this command will remove all its datasets, as well as all previous job reports. Are you sure you want to continue?')}) %} +

{% endif %} {% endblock %} - +