From 7164cfa37a049b550481f4bd2d2f03cbef86a49e Mon Sep 17 00:00:00 2001 From: Tom Hubrecht Date: Mon, 22 May 2023 20:12:47 +0200 Subject: [PATCH] =?UTF-8?q?feat(kfet):=20Ajout=20d'un=20formulaire=20de=20?= =?UTF-8?q?demande=20de=20soir=C3=A9e?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kfet/forms.py | 28 ++++++++++++++++ kfet/templates/kfet/demande_soiree.html | 28 ++++++++++++++++ kfet/templates/kfet/mails/demande_soiree.txt | 16 +++++++++ kfet/urls.py | 3 ++ kfet/views.py | 35 ++++++++++++++++++++ 5 files changed, 110 insertions(+) create mode 100644 kfet/templates/kfet/demande_soiree.html create mode 100644 kfet/templates/kfet/mails/demande_soiree.txt diff --git a/kfet/forms.py b/kfet/forms.py index ccc2ecbf..29442cf8 100644 --- a/kfet/forms.py +++ b/kfet/forms.py @@ -58,6 +58,34 @@ class ContactForm(forms.Form): return self.cleaned_data["from_email"] or "Anonyme " +class DemandeSoireeForm(forms.Form): + HORAIRE_CHOICES = map(lambda s: (s, s), ("22h", "23h", "00h", "01h", "02h", "03h")) + SERVICE_CHOICES = ( + ("K-Fêt", "K-Fêt standard (L'équipe K-Fêt fait le service normal au bar)"), + ("Kalô", "Type Kalô (Vous ramenez vos propres boissons et servez vous-mêmes)"), + ) + + nom = forms.CharField() + from_email = forms.EmailField(label="Adresse mail de contact") + + contact_boum = forms.BooleanField(label="Contacter le Boum", required=False) + contact_pls = forms.BooleanField(label="Contacter PLS", required=False) + + theme = forms.CharField(label="Thème de la soirée") + horaire_fin = forms.ChoiceField(label="Horaire de fin", choices=HORAIRE_CHOICES) + service = forms.ChoiceField(label="Mode de service", choices=SERVICE_CHOICES) + date = forms.CharField(label="Date souhaitée") + + respo1 = forms.CharField(label="Nom de la personne respo n°1") + respo2 = forms.CharField(label="Nom de la personne respo n°2") + respo3 = forms.CharField(label="Nom de la personne respo n°3") + respo4 = forms.CharField(label="Nom de la personne respo n°4") + + remarques = forms.CharField( + label="Remarques supplémentaires", widget=forms.Textarea + ) + + # ----- # Account forms # ----- diff --git a/kfet/templates/kfet/demande_soiree.html b/kfet/templates/kfet/demande_soiree.html new file mode 100644 index 00000000..0ac0dd69 --- /dev/null +++ b/kfet/templates/kfet/demande_soiree.html @@ -0,0 +1,28 @@ +{% extends "kfet/base_form.html" %} + +{% block extra_head %} +{{ negative_form.media }} +{% endblock %} + +{% block title %} + Effectuer une demande de soirée +{% endblock %} + +{% block header-title %} + Effectuer une demande de soirée +{% endblock %} + +{% block footer %} +{% include "kfet/base_footer.html" %} +{% endblock %} + +{% block main %} + +
+ {% csrf_token %} + {% include 'kfet/form_snippet.html' %} + + {% include 'kfet/form_submit_snippet.html' with value="Envoyer" %} +
+ +{% endblock %} diff --git a/kfet/templates/kfet/mails/demande_soiree.txt b/kfet/templates/kfet/mails/demande_soiree.txt new file mode 100644 index 00000000..9fd6d635 --- /dev/null +++ b/kfet/templates/kfet/mails/demande_soiree.txt @@ -0,0 +1,16 @@ +Bonjour, + +J'aimerais organiser une soirée le {{ date }}, au thème « {{ theme|safe }} », en K-Fêt. +Elle se terminerait à {{ horaire_fin }}, et le service serait en mode {{ service }}. + +Les 4 responsables de la soirée seraient : +- {{ respo1 }} +- {{ respo2 }} +- {{ respo3 }} +- {{ respo4 }} + +Quelques remarques supplémentaires : +{{ remarques|safe }} + +Bien cordialement, +{{ nom|safe }} diff --git a/kfet/urls.py b/kfet/urls.py index 57a68f32..f33cea03 100644 --- a/kfet/urls.py +++ b/kfet/urls.py @@ -10,6 +10,9 @@ urlpatterns = [ path("login/generic", views.login_generic, name="kfet.login.generic"), path("history", views.history, name="kfet.history"), path("contact", views.ContactView.as_view(), name="kfet.contact"), + path( + "demande-soiree", views.DemandeSoireeView.as_view(), name="kfet.demande-soiree" + ), # ----- # Account urls # ----- diff --git a/kfet/views.py b/kfet/views.py index ad320a7f..94e9e5fe 100644 --- a/kfet/views.py +++ b/kfet/views.py @@ -35,6 +35,7 @@ from django.http import ( JsonResponse, ) from django.shortcuts import get_object_or_404, redirect, render +from django.template import loader from django.urls import reverse, reverse_lazy from django.utils import timezone from django.utils.decorators import method_decorator @@ -65,6 +66,7 @@ from kfet.forms import ( CheckoutStatementUpdateForm, CofForm, ContactForm, + DemandeSoireeForm, FilterHistoryForm, InventoryArticleForm, KFetConfigForm, @@ -137,6 +139,39 @@ class ContactView(FormView): return super().form_valid(form) +class DemandeSoireeView(FormView): + template_name = "kfet/demande_soiree.html" + form_class = DemandeSoireeForm + success_url = reverse_lazy("kfet.demande-soiree") + + def form_valid(self, form): + destinataires = ["chefs-k-fet@ens.psl.eu"] + + if form.cleaned_data["contact_boum"]: + destinataires.append("boum@ens.psl.eu") + + if form.cleaned_data["contact_pls"]: + destinataires.append("pls@ens.psl.eu") + + # Envoie un mail lorsque le formulaire est valide + EmailMessage( + f"Demande de soirée le {form.cleaned_data['date']}", + loader.render_to_string( + "kfet/mails/demande_soiree.txt", context=form.cleaned_data + ), + from_email=form.cleaned_data["from_email"], + to=destinataires, + cc=[form.cleaned_data["from_email"]], + ).send() + + messages.success( + self.request, + "Votre demande de soirée a bien été envoyée.", + ) + + return super().form_valid(form) + + # ----- # Account views # -----