2024-11-14 01:07:19 +01:00
|
|
|
from django.contrib.messages.views import SuccessMessageMixin
|
|
|
|
from django.urls import reverse_lazy
|
|
|
|
from django.views.generic.edit import CreateView
|
2024-11-13 12:19:06 +01:00
|
|
|
|
2024-11-14 01:07:19 +01:00
|
|
|
from .models import Presence
|
2024-11-13 12:19:06 +01:00
|
|
|
|
2024-11-14 01:07:19 +01:00
|
|
|
|
|
|
|
class HomeView(SuccessMessageMixin, CreateView):
|
2024-11-13 12:19:06 +01:00
|
|
|
"""Home page"""
|
|
|
|
|
|
|
|
template_name = "phd/home.html"
|
2024-11-14 01:07:19 +01:00
|
|
|
model = Presence
|
|
|
|
fields = ["name"]
|
|
|
|
success_url = reverse_lazy("home")
|
|
|
|
success_message = "Super, merci d'avoir prévenu !"
|
|
|
|
|
|
|
|
def get_context_data(self, **kwargs):
|
|
|
|
context = super().get_context_data(**kwargs)
|
|
|
|
context["has_replied"] = self.request.session.get("presence_has_replied", False)
|
|
|
|
return context
|
|
|
|
|
|
|
|
def form_valid(self, form):
|
|
|
|
self.request.session["presence_has_replied"] = True
|
|
|
|
return super().form_valid(form)
|