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 simulation link #101

Merged
merged 1 commit into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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")
Loading