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 0000000000000000000000000000000000000000..4ba497f91be7d69c7a763dddb15b36a7faf6bf04 --- /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 d24d9fe009235b233500c637ee5dbb3c872fce38..c7f4b707437a8295a54509ba1e08261c3b02d8b0 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 182e8fd99445576402b6e5d7d7e7119ecbca128a..123e930fed5e7f19d7e9e6ee3c0d374fd206f415 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 b43000564fcbbaaf1596c6d08d1643b7baf00bef..8414f4cb581b2d82bd5f28b2bb64e4f2f1a2b798 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: