diff --git a/src/agenda_culturel/locale/fr/LC_MESSAGES/django.po b/src/agenda_culturel/locale/fr/LC_MESSAGES/django.po index fbf71b7..512c255 100644 --- a/src/agenda_culturel/locale/fr/LC_MESSAGES/django.po +++ b/src/agenda_culturel/locale/fr/LC_MESSAGES/django.po @@ -247,4 +247,7 @@ msgid "The start date cannot be earler than today." msgstr "La date de début ne peut pas être avant aujourd'hui." 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." \ No newline at end of file +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." \ No newline at end of file diff --git a/src/agenda_culturel/views.py b/src/agenda_culturel/views.py index 3aef350..610c9f5 100644 --- a/src/agenda_culturel/views.py +++ b/src/agenda_culturel/views.py @@ -1,10 +1,11 @@ from django.shortcuts import render, get_object_or_404 from django.views.generic import ListView, DetailView, FormView 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 import forms from django.contrib.postgres.search import SearchQuery, SearchHeadline +from django.core.exceptions import PermissionDenied from .forms import EventSubmissionModelForm, EventForm @@ -330,11 +331,12 @@ class StaticContentUpdateView(SuccessMessageMixin, LoginRequiredMixin, UpdateVie -class EventCreateView(CreateView): +class EventCreateView(SuccessMessageMixin, CreateView): model = Event form_class = EventForm 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): kwargs = super().get_form_kwargs() @@ -351,6 +353,11 @@ class EventCreateView(CreateView): 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): @@ -365,7 +372,7 @@ class EventDeleteView(SuccessMessageMixin, LoginRequiredMixin, DeleteView): success_message = _('The event has been successfully deleted.') -class EventDetailView(DetailView): +class EventDetailView(UserPassesTestMixin, DetailView): model = Event template_name = "agenda_culturel/page-event.html" @@ -374,6 +381,9 @@ class EventDetailView(DetailView): context["now"] = timezone.now() return context + def test_func(self): + return self.request.user.is_authenticated or self.get_object().status != Event.STATUS.PUBLISHED + class EventSubmissionFormView(FormView): form_class = EventSubmissionModelForm