Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delete Datastore Table Button #197

Merged
merged 9 commits into from
Feb 1, 2024
22 changes: 22 additions & 0 deletions ckanext/xloader/templates/xloader/confirm_datastore_delete.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{% extends "page.html" %}

{% block subtitle %}{{ _("Confirm Delete") }}{% endblock %}

{% block maintag %}<div class="row" role="main">{% endblock %}

{% block main_content %}
<section class="module col-md-6 col-md-offset-3">
<div class="module-content">
{% block form %}
<p>{{ _('Are you sure you want to delete the DataStore and Data Dictionary?') }}</p>
<p class="form-actions">
<form action="{{ h.url_for('xloader.delete_datastore_table', id=package_id, resource_id=resource_id) }}" method="post">
{{ h.csrf_input() if 'csrf_input' in h }}
<button class="btn btn-danger" type="submit" name="cancel" >{{ _('Cancel') }}</button>
<button class="btn btn-primary" type="submit" name="delete" >{{ _('Confirm Delete') }}</button>
</form>
</p>
{% endblock %}
</div>
</section>
{% endblock %}
16 changes: 15 additions & 1 deletion ckanext/xloader/templates/xloader/resource_data.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,24 @@
{% block primary_content_inner %}

{% set action = h.url_for('xloader.resource_data', id=pkg.name, resource_id=res.id) %}
{% set delete_action = h.url_for('xloader.delete_datastore_table', id=pkg.id, resource_id=res.id) %}
JVickery-TBS marked this conversation as resolved.
Show resolved Hide resolved
{% set show_table = true %}

{% block delete_ds_button %}
<form method="post" action="{{ delete_action }}" class="mb-3 d-inline-block">
{{ h.csrf_input() if 'csrf_input' in h }}
<a href="{{ h.url_for('xloader.delete_datastore_table', id=pkg.id, resource_id=res.id) }}"
class="btn btn-danger pull-left"
type="submit"
data-module="confirm-action"
data-module-with-data=true
data-module-content="{{ _('Are you sure you want to delete the DataStore and Data Dictionary?') }}"
>{% block delete_datastore_button_text %}<i class="fa fa-remove"></i>{{ _('Delete from DataStore') }}{% endblock %}</a>
</form>
{% endblock %}

{% block upload_ds_button %}
<form method="post" action="{{ action }}" class="datapusher-form">
<form method="post" action="{{ action }}" class="datapusher-form mb-3 d-inline-block">
{{ h.csrf_input() if 'csrf_input' in h }}
<button class="btn btn-primary" name="save" type="submit">
<i class="fa fa-cloud-upload"></i> {{ _('Upload to DataStore') }}
Expand Down
36 changes: 36 additions & 0 deletions ckanext/xloader/views.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
from flask import Blueprint

from ckanapi import LocalCKAN
from ckan.plugins.toolkit import _, h, g, render, request, abort, NotAuthorized, get_action

import ckanext.xloader.utils as utils


Expand All @@ -13,3 +16,36 @@ def get_blueprints():
@xloader.route("/dataset/<id>/resource_data/<resource_id>", methods=("GET", "POST"))
def resource_data(id, resource_id):
return utils.resource_data(id, resource_id)


@xloader.route("/dataset/<id>/delete-datastore/<resource_id>", 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)

if request.method == 'POST':
context = {"user": g.user}

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)