+ {% block form %}
+
+ {{ _('Are you sure you want to delete the DataStore and Data Dictionary?') }}
++
+ + {% endblock %} +
diff --git a/ckanext/xloader/views.py b/ckanext/xloader/views.py
index 5a56322c..399d6ad6 100644
--- a/ckanext/xloader/views.py
+++ b/ckanext/xloader/views.py
@@ -1,5 +1,7 @@
from flask import Blueprint, request
+from ckan.plugins.toolkit import _, h, g, render, request, abort, NotAuthorized, get_action, ObjectNotFound
+
import ckanext.xloader.utils as utils
@@ -21,3 +23,43 @@ def resource_data(id, resource_id):
except ValueError:
rows = None
return utils.resource_data(id, resource_id, rows)
+
+
+@xloader.route("/dataset//delete-datastore/", methods=("GET", "POST"))
+def delete_datastore_table(id, resource_id):
+ if u'cancel' in request.form:
+ return h.redirect_to(u'xloader.resource_data', id=id, resource_id=resource_id)
+
+ context = {"user": g.user}
+
+ try:
+ res_dict = get_action('resource_show')(context, {"id": resource_id})
+ if res_dict.get('package_id') != id:
+ raise ObjectNotFound
+ except ObjectNotFound:
+ return abort(404, _(u'Resource not found'))
+
+ if request.method == 'POST':
+ try:
+ get_action('datastore_delete')(context, {
+ "resource_id": resource_id,
+ "force": True})
+ except NotAuthorized:
+ return abort(403, _(u'Unauthorized to delete resource %s') % resource_id)
+
+ h.flash_notice(_(u'DataStore and Data Dictionary deleted for resource %s') % resource_id)
+
+ return h.redirect_to(
+ 'xloader.resource_data',
+ id=id,
+ resource_id=resource_id
+ )
+ else:
+ g.resource_id = resource_id
+ g.package_id = id
+
+ extra_vars = {
+ u"resource_id": resource_id,
+ u"package_id": id
+ }
+ return render(u'xloader/confirm_datastore_delete.html', extra_vars)