From af6ffc47ca1c73735a0fa3b471fb610b5688f468 Mon Sep 17 00:00:00 2001 From: Frank Sauerburger <frank@sauerburger.com> Date: Wed, 6 Jan 2021 19:53:13 +0100 Subject: [PATCH] Add plot delete button --- .../uhepp_vault/plot_confirm_delete.html | 20 +++++++++++++++++++ .../templates/uhepp_vault/plot_detail.html | 20 ++++++++++++++----- uhepp_org/uhepp_vault/urls.py | 1 + uhepp_org/uhepp_vault/views.py | 13 ++++++++++++ 4 files changed, 49 insertions(+), 5 deletions(-) create mode 100644 uhepp_org/uhepp_vault/templates/uhepp_vault/plot_confirm_delete.html diff --git a/uhepp_org/uhepp_vault/templates/uhepp_vault/plot_confirm_delete.html b/uhepp_org/uhepp_vault/templates/uhepp_vault/plot_confirm_delete.html new file mode 100644 index 0000000..4ba497f --- /dev/null +++ b/uhepp_org/uhepp_vault/templates/uhepp_vault/plot_confirm_delete.html @@ -0,0 +1,20 @@ +{% extends 'uhepp_vault/base.html' %} + +{% block content %} +<nav aria-label="breadcrumb" class="d-none d-sm-block"> + <ol class="breadcrumb my-2"> + <li class="breadcrumb-item"><a href="/">Home</a></li> + <li class="breadcrumb-item"><a href="{% url 'uhepp_vault:user-detail' plot.collection.owner.username %}">{{ plot.collection.owner }}</a></li> + <li class="breadcrumb-item"><a href="{% url 'uhepp_vault:collection-detail' plot.collection.id %}">{{ plot.collection.title }}</a></li> + <li class="breadcrumb-item active"><a href="{% url 'uhepp_vault:plot-detail' plot.uuid %}">{{ plot }}</a></li> + </ol> +</nav> + +<h1>Delete plot</h1> + +<form method="post">{% csrf_token %} + <p>Are you sure you want to delete plot <b>{{ plot }}</b>?</p> + <button type="submit" class="btn btn-outline-danger">Delete</button> +</form> + +{% endblock %} diff --git a/uhepp_org/uhepp_vault/templates/uhepp_vault/plot_detail.html b/uhepp_org/uhepp_vault/templates/uhepp_vault/plot_detail.html index d24d9fe..c7f4b70 100644 --- a/uhepp_org/uhepp_vault/templates/uhepp_vault/plot_detail.html +++ b/uhepp_org/uhepp_vault/templates/uhepp_vault/plot_detail.html @@ -11,11 +11,21 @@ </ol> </nav> -<h1>{{ plot }} -<i class="text-muted fas {% if plot.collection.visibility >= 30 %} fa-globe-europe -{% elif plot.collection.visibility >= 20 %} fa-shield-alt -{% elif plot.collection.visibility >= 10 %} fa-lock -{% endif %}"></i></h1> +<h1 class="controls-head"> + <span> + {{ plot }} + <i class="text-muted fas {% if plot.collection.visibility >= 30 %} fa-globe-europe + {% elif plot.collection.visibility >= 20 %} fa-shield-alt + {% elif plot.collection.visibility >= 10 %} fa-lock + {% endif %}"></i> + </span> + {% if plot.collection.owner.pk == user.pk %} + <span> + <a class="btn btn-outline-danger" href="{% url 'uhepp_vault:plot-delete' plot.uuid %}"> + <i class="fas fa-trash"></i> + </a> + </span> + {% endif %}</h1> <div class="d-flex"> <span class="d-none d-md-inline">UUID: {{ plot.uuid }}</span> diff --git a/uhepp_org/uhepp_vault/urls.py b/uhepp_org/uhepp_vault/urls.py index 182e8fd..123e930 100644 --- a/uhepp_org/uhepp_vault/urls.py +++ b/uhepp_org/uhepp_vault/urls.py @@ -22,5 +22,6 @@ urlpatterns = [ path('c/<str:pk>/delete', views.CollectionDeleteView.as_view(), name='collection-delete'), path('p/', views.PlotListView.as_view(), name='plot-list'), path('p/<str:uuid>', views.PlotDetail.as_view(), name='plot-detail'), + path('p/<str:uuid>/delete', views.PlotDeleteView.as_view(), name='plot-delete'), path('p/<str:uuid>/download', views.plot_download, name='plot-download'), ] diff --git a/uhepp_org/uhepp_vault/views.py b/uhepp_org/uhepp_vault/views.py index b430005..8414f4c 100644 --- a/uhepp_org/uhepp_vault/views.py +++ b/uhepp_org/uhepp_vault/views.py @@ -216,6 +216,19 @@ class PlotDetail(generic.DetailView): raise original return redirect('%s?next=%s' % (settings.LOGIN_URL, request.path)) +class PlotDeleteView(LoginRequiredMixin, generic.DeleteView): + model = Plot + slug_field = 'uuid' + slug_url_kwarg = 'uuid' + + def get_success_url(self): + return reverse_lazy('uhepp_vault:collection-detail', + args=[self.object.collection.pk]) + + def get_queryset(self): + queryset = Plot.objects.filter(collection__owner=self.request.user) + return queryset + def plot_download(request, uuid): if request.user.is_anonymous: -- GitLab