Skip to content

Commit

Permalink
Add delete simulation link
Browse files Browse the repository at this point in the history
  • Loading branch information
svenseeberg committed Jan 30, 2024
1 parent d62f553 commit 79b39e8
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ <h2>List of Leeway Simulations</h2>
{% endif %}
{% if simulation.img %}<a href="{{ simulation.img.url }}">Image</a>{% endif %}
{% if simulation.netcdf %}<a href="{{ simulation.netcdf.url }}">NetCDF</a>{% endif %}
<a href="{% url "simulation_delete" pk=simulation.pk %}">Delete</a>
</td>
</tr>
{% endfor %}
Expand Down
6 changes: 6 additions & 0 deletions opendrift_leeway_webgui/leeway/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from .views import (
IndexRedirectView,
LeewaySimulationCreateView,
LeewaySimulationDeleteView,
LeewaySimulationDetailView,
LeewaySimulationDocumentation,
LeewaySimulationListView,
Expand All @@ -38,6 +39,11 @@
LeewaySimulationDetailView.as_view(),
name="simulation_detail",
),
path(
"<pk>/delete/",
LeewaySimulationDeleteView.as_view(),
name="simulation_delete",
),
]
),
),
Expand Down
18 changes: 17 additions & 1 deletion opendrift_leeway_webgui/leeway/views.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
from django.conf import settings
from django.contrib import messages
from django.contrib.auth.mixins import LoginRequiredMixin
from django.http import HttpResponseForbidden, HttpResponseRedirect
from django.urls import reverse_lazy
from django.views.generic import TemplateView
from django.views.generic.base import RedirectView
from django.views.generic.detail import DetailView
from django.views.generic.edit import CreateView
from django.views.generic.edit import CreateView, DeleteView
from django.views.generic.list import ListView

from .forms import LeewaySimulationForm
Expand Down Expand Up @@ -102,3 +103,18 @@ class LeewaySimulationDetailView(LoginRequiredMixin, DetailView):

#: The model for this detail view
model = LeewaySimulation


class LeewaySimulationDeleteView(LoginRequiredMixin, DeleteView):
"""
View for rendering the simulation details
"""

model = LeewaySimulation
success_url = reverse_lazy("simulation_list")

def get(self, request, *args, **kwargs):
if self.get_object().user == request.user:
self.object.delete()
return HttpResponseRedirect("/simulations")
return HttpResponseForbidden("Cannot delete other's simulations")

0 comments on commit 79b39e8

Please sign in to comment.