Skip to content

Commit 5295cac

Browse files
authored
fix: photo upload (#981)
1 parent 764b125 commit 5295cac

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

bullet/bullet_admin/views/albums.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
from bullet_admin.access import PhotoUploadAccess
1313
from bullet_admin.forms.album import AlbumForm
14-
from bullet_admin.mixins import RedirectBackMixin
1514
from bullet_admin.utils import get_active_competition
1615
from bullet_admin.views import GenericDelete, GenericForm, GenericList
1716

@@ -65,7 +64,9 @@ def get_form_kwargs(self):
6564

6665
def form_valid(self, form):
6766
album: Album = form.save(commit=False)
67+
self.object = album
6868
album.competition = get_active_competition(self.request)
69+
album.save()
6970
for file in form.cleaned_data["photo_files"]:
7071
photo = Photo(album=album, image=file)
7172

@@ -77,11 +78,13 @@ def form_valid(self, form):
7778
).replace(tzinfo=timezone.utc)
7879

7980
photo.save()
80-
album.save()
8181
return HttpResponseRedirect(self.get_success_url())
8282

83+
def get_success_url(self):
84+
return reverse("badmin:album_edit", kwargs={"pk": self.object.id})
85+
8386

84-
class AlbumUpdateView(PhotoUploadAccess, RedirectBackMixin, AlbumFormMixin, UpdateView):
87+
class AlbumUpdateView(PhotoUploadAccess, AlbumFormMixin, UpdateView):
8588
form_title = "Edit album"
8689

8790
def get_queryset(self):
@@ -93,7 +96,7 @@ def form_valid(self, form):
9396
return ret
9497

9598

96-
class AlbumCreateView(PhotoUploadAccess, RedirectBackMixin, AlbumFormMixin, CreateView):
99+
class AlbumCreateView(PhotoUploadAccess, AlbumFormMixin, CreateView):
97100
form_title = "New album"
98101

99102
def form_valid(self, form):
@@ -102,8 +105,9 @@ def form_valid(self, form):
102105
return ret
103106

104107

105-
class AlbumDeleteView(PhotoUploadAccess, RedirectBackMixin, GenericDelete, DeleteView):
108+
class AlbumDeleteView(PhotoUploadAccess, GenericDelete, DeleteView):
106109
model = Album
110+
success_url = reverse_lazy("badmin:album_list")
107111

108112
def form_valid(self, form):
109113
super().form_valid(form)

0 commit comments

Comments
 (0)