From d6727fb8ad06f2c407e644cfc476953c11a56cc0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Zahradn=C3=ADk?= Date: Tue, 21 Jan 2025 10:27:25 +0100 Subject: [PATCH] fix photo uploading --- bullet/bullet_admin/views/albums.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/bullet/bullet_admin/views/albums.py b/bullet/bullet_admin/views/albums.py index b7ecd853..b3db8025 100644 --- a/bullet/bullet_admin/views/albums.py +++ b/bullet/bullet_admin/views/albums.py @@ -11,7 +11,6 @@ from bullet_admin.access import PhotoUploadAccess from bullet_admin.forms.album import AlbumForm -from bullet_admin.mixins import RedirectBackMixin from bullet_admin.utils import get_active_competition from bullet_admin.views import GenericDelete, GenericForm, GenericList @@ -65,7 +64,9 @@ def get_form_kwargs(self): def form_valid(self, form): album: Album = form.save(commit=False) + self.object = album album.competition = get_active_competition(self.request) + album.save() for file in form.cleaned_data["photo_files"]: photo = Photo(album=album, image=file) @@ -77,11 +78,13 @@ def form_valid(self, form): ).replace(tzinfo=timezone.utc) photo.save() - album.save() return HttpResponseRedirect(self.get_success_url()) + def get_success_url(self): + return reverse("badmin:album_edit", kwargs={"pk": self.object.id}) + -class AlbumUpdateView(PhotoUploadAccess, RedirectBackMixin, AlbumFormMixin, UpdateView): +class AlbumUpdateView(PhotoUploadAccess, AlbumFormMixin, UpdateView): form_title = "Edit album" def get_queryset(self): @@ -93,7 +96,7 @@ def form_valid(self, form): return ret -class AlbumCreateView(PhotoUploadAccess, RedirectBackMixin, AlbumFormMixin, CreateView): +class AlbumCreateView(PhotoUploadAccess, AlbumFormMixin, CreateView): form_title = "New album" def form_valid(self, form): @@ -102,8 +105,9 @@ def form_valid(self, form): return ret -class AlbumDeleteView(PhotoUploadAccess, RedirectBackMixin, GenericDelete, DeleteView): +class AlbumDeleteView(PhotoUploadAccess, GenericDelete, DeleteView): model = Album + success_url = reverse_lazy("badmin:album_list") def form_valid(self, form): super().form_valid(form)