Skip to content
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
14 changes: 9 additions & 5 deletions bullet/bullet_admin/views/albums.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)

Expand All @@ -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):
Expand All @@ -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):
Expand All @@ -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)
Expand Down
Loading