django-web-galleries/django_web_galleries/web_galleries/views.py
reverend c5dfb4f926 Squashed commit of the following:
commit 4c5a5fee8d
Author: reverend <reverend@reverend2048.de>
Date:   Sun Dec 18 09:24:15 2022 +0100

commit 17647bf4b7
Author: reverend <reverend@reverend2048.de>
Date:   Sun Dec 18 09:23:36 2022 +0100

commit 4deeb3d773
Author: reverend <reverend@reverend2048.de>
Date:   Sun Dec 18 09:23:06 2022 +0100

commit 5342e62bcb
Author: reverend <reverend@reverend2048.de>
Date:   Sun Dec 18 09:22:44 2022 +0100

commit 02512c1677
Author: reverend <reverend@reverend2048.de>
Date:   Sun Dec 18 09:21:57 2022 +0100
2022-12-18 09:24:55 +01:00

56 lines
1.3 KiB
Python

import secrets
from django.views import View
from django.views.generic.list import ListView
from django.shortcuts import render, redirect
from django.urls import reverse
from .forms import ImageUploadForm
from .models import Image
class ImageUploadView(View):
def get(self, request):
form = ImageUploadForm()
return render(
request,
'upload_image/upload.html',
{
'form': form
}
)
def post(self, request):
form = ImageUploadForm(
request.POST,
request.FILES
)
if form.is_valid():
image = form.save(commit=False)
if image.private:
image.access_code = secrets.token_hex(32)
image.save()
return redirect(
reverse('home')
)
else:
form = ImageUploadForm()
return render(
request,
'upload_image/upload.html',
{
'form': form
}
)
class PublicImageListView(ListView):
model = Image
paginate_by = 20
context_object_name = 'images'
template_name = 'list_images/image_list.html'
def get_queryset(self):
return Image.objects.all().filter(private=False)