* Un événement non publié ne peut pas être vu par un utilisateur non connecté, même s'il en a l'adresse
* Si un utilisateur non connecté créé un événement, on le renvoie vers la page d'accueil
This commit is contained in:
parent
7f8bc23dac
commit
c26140e088
@ -248,3 +248,6 @@ msgstr "La date de début ne peut pas être avant aujourd'hui."
|
|||||||
|
|
||||||
msgid "The end time cannot be earlier than the start time."
|
msgid "The end time cannot be earlier than the start time."
|
||||||
msgstr "L'heure de fin ne peut pas être avant l'heure de début."
|
msgstr "L'heure de fin ne peut pas être avant l'heure de début."
|
||||||
|
|
||||||
|
msgid "The event has been submitted and will be published as soon as it has been validated by the moderation team."
|
||||||
|
msgstr "L'événement a été soumis et sera publié dès qu'il aura été validé par l'équipe de modération."
|
@ -1,10 +1,11 @@
|
|||||||
from django.shortcuts import render, get_object_or_404
|
from django.shortcuts import render, get_object_or_404
|
||||||
from django.views.generic import ListView, DetailView, FormView
|
from django.views.generic import ListView, DetailView, FormView
|
||||||
from django.views.generic.edit import CreateView, UpdateView, DeleteView
|
from django.views.generic.edit import CreateView, UpdateView, DeleteView
|
||||||
from django.contrib.auth.mixins import LoginRequiredMixin
|
from django.contrib.auth.mixins import LoginRequiredMixin, UserPassesTestMixin
|
||||||
from django.http import QueryDict
|
from django.http import QueryDict
|
||||||
from django import forms
|
from django import forms
|
||||||
from django.contrib.postgres.search import SearchQuery, SearchHeadline
|
from django.contrib.postgres.search import SearchQuery, SearchHeadline
|
||||||
|
from django.core.exceptions import PermissionDenied
|
||||||
|
|
||||||
|
|
||||||
from .forms import EventSubmissionModelForm, EventForm
|
from .forms import EventSubmissionModelForm, EventForm
|
||||||
@ -330,11 +331,12 @@ class StaticContentUpdateView(SuccessMessageMixin, LoginRequiredMixin, UpdateVie
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
class EventCreateView(CreateView):
|
class EventCreateView(SuccessMessageMixin, CreateView):
|
||||||
model = Event
|
model = Event
|
||||||
|
|
||||||
form_class = EventForm
|
form_class = EventForm
|
||||||
template_name_suffix = "_create_form"
|
template_name_suffix = "_create_form"
|
||||||
|
success_message = _('The event has been submitted and will be published as soon as it has been validated by the moderation team.')
|
||||||
|
|
||||||
def get_form_kwargs(self):
|
def get_form_kwargs(self):
|
||||||
kwargs = super().get_form_kwargs()
|
kwargs = super().get_form_kwargs()
|
||||||
@ -351,6 +353,11 @@ class EventCreateView(CreateView):
|
|||||||
return initial
|
return initial
|
||||||
|
|
||||||
|
|
||||||
|
def get_success_url(self, **kwargs):
|
||||||
|
if self.request.user.is_authenticated:
|
||||||
|
return self.object.get_absolute_url()
|
||||||
|
else:
|
||||||
|
return reverse_lazy("home")
|
||||||
|
|
||||||
|
|
||||||
class EventUpdateView(SuccessMessageMixin, LoginRequiredMixin, UpdateView):
|
class EventUpdateView(SuccessMessageMixin, LoginRequiredMixin, UpdateView):
|
||||||
@ -365,7 +372,7 @@ class EventDeleteView(SuccessMessageMixin, LoginRequiredMixin, DeleteView):
|
|||||||
success_message = _('The event has been successfully deleted.')
|
success_message = _('The event has been successfully deleted.')
|
||||||
|
|
||||||
|
|
||||||
class EventDetailView(DetailView):
|
class EventDetailView(UserPassesTestMixin, DetailView):
|
||||||
model = Event
|
model = Event
|
||||||
template_name = "agenda_culturel/page-event.html"
|
template_name = "agenda_culturel/page-event.html"
|
||||||
|
|
||||||
@ -374,6 +381,9 @@ class EventDetailView(DetailView):
|
|||||||
context["now"] = timezone.now()
|
context["now"] = timezone.now()
|
||||||
return context
|
return context
|
||||||
|
|
||||||
|
def test_func(self):
|
||||||
|
return self.request.user.is_authenticated or self.get_object().status != Event.STATUS.PUBLISHED
|
||||||
|
|
||||||
|
|
||||||
class EventSubmissionFormView(FormView):
|
class EventSubmissionFormView(FormView):
|
||||||
form_class = EventSubmissionModelForm
|
form_class = EventSubmissionModelForm
|
||||||
|
Loading…
Reference in New Issue
Block a user