feat(kfet): Ajoute un formulaire de contact

This commit is contained in:
Tom Hubrecht 2023-05-19 20:15:50 +02:00
parent 83078d4726
commit e50249355d
5 changed files with 77 additions and 7 deletions

View file

@ -45,6 +45,19 @@ class DateTimeWidget(forms.DateTimeInput):
js = ("kfet/vendor/bootstrap/bootstrap-datetimepicker.min.js",)
class ContactForm(forms.Form):
from_email = forms.EmailField(
label="Adresse mail",
help_text="Si aucune adresse mail n'est renseignée, la soumission sera anonyme.",
required=False,
)
subject = forms.CharField(label="Objet", required=True)
message = forms.CharField(widget=forms.Textarea, required=True)
def clean_from_email(self):
return self.cleaned_data["from_email"] or "Anonyme <k-fet@ens.psl.eu>"
# -----
# Account forms
# -----

View file

@ -1,17 +1,13 @@
{% load wagtailcore_tags %}
{% with "k-fet@ens.fr" as kfet_mail %}
<footer class="row">
<div class="footer">
<span>
<a href="{% slugurl "mentions-legales" %}">Mentions légales</a>
<b><a href="{% url "kfet.contact" %}">Formulaire de contact</a></b>
</span>
|
<span>
En cas de pépin : <a href="mailto:{{ kfet_mail }}"><tt>{{ kfet_mail }}</tt></a>
<a href="{% slugurl "mentions-legales" %}">Mentions légales</a>
</span>
</div>
</div>
{% endwith %}
</footer>

View file

@ -0,0 +1,36 @@
{% extends "kfet/base_form.html" %}
{% block extra_head %}
{{ negative_form.media }}
{% endblock %}
{% block title %}
Contacter la K-Fêt
{% endblock %}
{% block header-title %}
Contacter la K-Fêt
{% endblock %}
{% block footer %}
{% include "kfet/base_footer.html" %}
{% endblock %}
{% block main %}
<div class="messages">
<div class="alert alert-info">
<b>Votre message sera envoyé aux Chef·fe·s et aux Wo·men K-Fêt.</b>
</div>
</div>
<br>
<form action="" method="post" class="form-horizontal" autocomplete="off">
{% csrf_token %}
{% include 'kfet/form_snippet.html' %}
{% include 'kfet/form_submit_snippet.html' with value="Envoyer" %}
</form>
{% endblock %}

View file

@ -9,6 +9,7 @@ register_converter(converters.TrigrammeConverter, "trigramme")
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"),
# -----
# Account urls
# -----

View file

@ -13,6 +13,7 @@ from django.contrib.auth.mixins import PermissionRequiredMixin
from django.contrib.auth.models import Permission, User
from django.contrib.messages.views import SuccessMessageMixin
from django.core.exceptions import SuspiciousOperation
from django.core.mail import EmailMessage
from django.db import transaction
from django.db.models import (
Count,
@ -63,6 +64,7 @@ from kfet.forms import (
CheckoutStatementCreateForm,
CheckoutStatementUpdateForm,
CofForm,
ContactForm,
FilterHistoryForm,
InventoryArticleForm,
KFetConfigForm,
@ -113,6 +115,28 @@ def put_cleaned_data_in_dict(dict, form):
dict[field] = form.cleaned_data[field]
class ContactView(FormView):
template_name = "kfet/contact.html"
form_class = ContactForm
success_url = reverse_lazy("kfet.contact")
def form_valid(self, form):
# Envoie un mail lorsque le formulaire est valide
EmailMessage(
form.cleaned_data["subject"],
form.cleaned_data["message"],
from_email=form.cleaned_data["from_email"],
to=("chefs-k-fet@ens.psl.eu",),
).send()
messages.success(
self.request,
"Votre message a bien été envoyé aux Wo·men K-Fêt.",
)
return super().form_valid(form)
# -----
# Account views
# -----