[#34] Integrate clear command with delete source

When deleting a source, if clear_source equals true in the context,
harvest_source_clear will be called. Default is false. The UI shows a
select with the two options.
This commit is contained in:
amercader 2013-05-20 14:30:22 +01:00
parent 6d5d0fbaae
commit 751409ab7d
3 changed files with 36 additions and 5 deletions

View File

@ -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:

View File

@ -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']})

View File

@ -85,12 +85,30 @@
<p class="form-actions">
{% 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?')}) %}
<a class="btn btn-danger pull-left" href="{% url_for 'harvest_delete', id=data.name %}" data-module="confirm-action" data-module-i18n="{{ locale }}">{% block delete_button_text %}{{ _('Delete') }}{% endblock %}</a>
{% 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?')}) %}
<div class="dropdown btn-group">
<a href="#" class="btn btn-danger dropdown-toggle" data-toggle="dropdown">
{{ _('Delete') }}
<span class="caret"></span>
</a>
<ul class="dropdown-menu">
<li>
<a href="{% url_for 'harvest_delete', id=data.name %}" data-module="confirm-action" data-module-i18n="{{ locale_delete }}">
{{ _('Delete source') }}
</a>
</li>
<li>
<a href="{% url_for 'harvest_delete', id=data.name %}?clear=True" data-module="confirm-action" data-module-i18n="{{ locale_clear }}">
{{ _('Delete and clear source') }}
</a>
</li>
</ul>
</div>
{% endif %}
{% endblock %}
<input id="save" name="save" value="Save" type="submit" class="btn btn-primary">
<input id="save" name="save" value="Save" type="submit" class="btn btn-primary pull-right">
</p>
</form>