Unify public and private gallery views, add author tabs and download
All checks were successful
Docker / build (release) Successful in 8s

This commit is contained in:
krek0 2026-05-07 17:22:06 +02:00
parent 317bad9068
commit 993421f52a
3 changed files with 36 additions and 13 deletions

View file

@ -221,29 +221,39 @@ class GalleryDownload(LoginRequiredMixin, DetailView):
# return response
class GalleryPublicView(DetailView):
model = Gallery
template_name = "photologue/gallery_detail.html"
class GalleryPublicView(GalleryDetailView):
def get_object(self):
return get_object_or_404(Gallery, public_token=self.kwargs["token"])
def get(self, request, *args, **kwargs):
def dispatch(self, request, *args, **kwargs):
if request.user.is_authenticated:
gallery = self.get_object()
return redirect("photologue:pl-gallery", slug=gallery.slug)
request.guest_mode = True
return super().get(request, *args, **kwargs)
# Bypass LoginRequiredMixin
return super(LoginRequiredMixin, self).dispatch(request, *args, **kwargs)
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context["photos"] = self.object.photos.filter(is_public=True).select_related("owner")
context["owners"] = []
context["guest_mode"] = True
context["photos"].update(view_count=F("view_count") + 1)
context.pop("can_resolve_censorship", None)
context.pop("public_url", None)
return context
class GalleryPublicDownload(View):
def get(self, request, token):
gallery = get_object_or_404(Gallery, public_token=token)
buffer = BytesIO()
with zipfile.ZipFile(buffer, "w") as zf:
for photo in gallery.photos.filter(is_public=True):
filename = os.path.basename(photo.image.name)
zf.write(photo.image.path, filename)
buffer.seek(0)
response = HttpResponse(buffer, content_type="application/zip")
response["Content-Disposition"] = f'attachment; filename="{gallery.slug}.zip"'
return response
class GalleryTokenView(LoginRequiredMixin, View):
def post(self, request, slug):
if not request.user.is_staff: