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 %}
20 changes: 19 additions & 1 deletion ckanext/xloader/templates/xloader/resource_data.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,35 @@
{% 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 upload_ds_button %}
<form method="post" action="{{ action }}" class="datapusher-form">
<form method="post" action="{{ action }}" class="datapusher-form mb-3 mr-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') }}
</button>
</form>
{% endblock %}

<div class="clear-fix mx-1 d-inline-block"></div>

{% block delete_ds_button %}
{% if res.datastore_active %}
<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"
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-trash-alt"></i> {{ _('Delete from DataStore') }}{% endblock %}</a>
</form>
{% endif %}
{% endblock %}

{% if status.error and status.error.message %}
{% set show_table = false %}
<div class="alert alert-error">
Expand Down
42 changes: 42 additions & 0 deletions ckanext/xloader/views.py
Original file line number Diff line number Diff line change
@@ -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


Expand All @@ -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/<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)

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)
Loading