Enable users to report without sending a mail

This commit is contained in:
Alexandre Iooss 2022-03-02 21:22:44 +01:00
parent f9c33e2cad
commit 2ad0c8dbc7
5 changed files with 119 additions and 6 deletions

View file

@ -18,6 +18,7 @@ from django.views.generic.dates import ArchiveIndexView, YearArchiveView
from django.views.generic.detail import DetailView
from django.views.generic.edit import FormView, DeleteView
from PIL import Image
from django.shortcuts import redirect
from .forms import UploadForm
from .models import Gallery, Photo, Tag
@ -68,6 +69,36 @@ class PhotoDeleteView(PermissionRequiredMixin, DeleteView):
return reverse_lazy('photologue:pl-gallery', args=[slug])
class PhotoReportView(LoginRequiredMixin, DetailView):
model = Photo
template_name = 'photologue/photo_confirm_report.html'
def post(self, request, *args, **kwargs):
"""
Make photo private on POST.
"""
# Mark photo as private
photo = self.get_object()
photo.is_public = False
photo.save()
# Get gallery
galleries = photo.galleries.all()
gallery_slug = galleries[0].slug if galleries else ''
if not gallery_slug:
url = reverse_lazy('photologue:pl-gallery-archive')
url = reverse_lazy('photologue:pl-gallery', args=[gallery_slug])
# Send mail to managers
mail_managers(
subject=f"Abuse report for photo id {photo.pk}",
message=f"{self.request.user.username} reported an abuse for `{photo.title}`: {url}#lg=1&slide={photo.pk}",
)
# Redirect to gallery
return redirect(url)
class TagDetail(LoginRequiredMixin, DetailView):
model = Tag