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

Modifie DeleteImages (préparation pour Django 4) #6574

Merged
merged 1 commit into from
Jan 14, 2024
Merged
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
11 changes: 5 additions & 6 deletions zds/gallery/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from django.core.exceptions import PermissionDenied
from django.urls import reverse
from django.http import Http404, HttpResponseRedirect
from django.views.generic import DeleteView, FormView, View
from django.views.generic import FormView, View
from django.shortcuts import redirect, get_object_or_404
from django.utils.translation import gettext_lazy as _
from django.contrib.auth.mixins import LoginRequiredMixin
Expand Down Expand Up @@ -398,24 +398,23 @@ def form_valid(self, form):
return super().form_valid(form)


class DeleteImages(ImageFromGalleryViewMixin, ImageUpdateOrDeleteMixin, LoggedWithReadWriteHability, DeleteView):
class DeleteImages(ImageFromGalleryViewMixin, ImageUpdateOrDeleteMixin, LoggedWithReadWriteHability, View):
"""Delete a given image"""

model = Image
http_method_names = ["post", "delete"]
http_method_names = ["post"]
must_write = True

def delete(self, request, *args, **kwargs):
def post(self, request, *args, **kwargs):
if "delete_multi" in request.POST:
list_items = request.POST.getlist("g_items")
Image.objects.filter(pk__in=list_items, gallery=self.gallery).delete()
elif "delete" in request.POST:
try:
self.get_image(self.request.POST.get("image"))
self.get_image(request.POST.get("image"))
self.perform_delete()
except Image.DoesNotExist:
raise Http404()

return redirect(self.gallery.get_absolute_url())


Expand Down