feat(kfet): Ajoute un formulaire de contact
This commit is contained in:
parent
83078d4726
commit
e50249355d
5 changed files with 77 additions and 7 deletions
|
@ -45,6 +45,19 @@ class DateTimeWidget(forms.DateTimeInput):
|
||||||
js = ("kfet/vendor/bootstrap/bootstrap-datetimepicker.min.js",)
|
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
|
# Account forms
|
||||||
# -----
|
# -----
|
||||||
|
|
|
@ -1,17 +1,13 @@
|
||||||
{% load wagtailcore_tags %}
|
{% load wagtailcore_tags %}
|
||||||
|
|
||||||
{% with "k-fet@ens.fr" as kfet_mail %}
|
|
||||||
|
|
||||||
<footer class="row">
|
<footer class="row">
|
||||||
<div class="footer">
|
<div class="footer">
|
||||||
<span>
|
<span>
|
||||||
<a href="{% slugurl "mentions-legales" %}">Mentions légales</a>
|
<b><a href="{% url "kfet.contact" %}">Formulaire de contact</a></b>
|
||||||
</span>
|
</span>
|
||||||
|
|
|
|
||||||
<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>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</footer>
|
||||||
|
|
||||||
{% endwith %}
|
|
||||||
|
|
36
kfet/templates/kfet/contact.html
Normal file
36
kfet/templates/kfet/contact.html
Normal 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 %}
|
|
@ -9,6 +9,7 @@ register_converter(converters.TrigrammeConverter, "trigramme")
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path("login/generic", views.login_generic, name="kfet.login.generic"),
|
path("login/generic", views.login_generic, name="kfet.login.generic"),
|
||||||
path("history", views.history, name="kfet.history"),
|
path("history", views.history, name="kfet.history"),
|
||||||
|
path("contact", views.ContactView.as_view(), name="kfet.contact"),
|
||||||
# -----
|
# -----
|
||||||
# Account urls
|
# Account urls
|
||||||
# -----
|
# -----
|
||||||
|
|
|
@ -13,6 +13,7 @@ from django.contrib.auth.mixins import PermissionRequiredMixin
|
||||||
from django.contrib.auth.models import Permission, User
|
from django.contrib.auth.models import Permission, User
|
||||||
from django.contrib.messages.views import SuccessMessageMixin
|
from django.contrib.messages.views import SuccessMessageMixin
|
||||||
from django.core.exceptions import SuspiciousOperation
|
from django.core.exceptions import SuspiciousOperation
|
||||||
|
from django.core.mail import EmailMessage
|
||||||
from django.db import transaction
|
from django.db import transaction
|
||||||
from django.db.models import (
|
from django.db.models import (
|
||||||
Count,
|
Count,
|
||||||
|
@ -63,6 +64,7 @@ from kfet.forms import (
|
||||||
CheckoutStatementCreateForm,
|
CheckoutStatementCreateForm,
|
||||||
CheckoutStatementUpdateForm,
|
CheckoutStatementUpdateForm,
|
||||||
CofForm,
|
CofForm,
|
||||||
|
ContactForm,
|
||||||
FilterHistoryForm,
|
FilterHistoryForm,
|
||||||
InventoryArticleForm,
|
InventoryArticleForm,
|
||||||
KFetConfigForm,
|
KFetConfigForm,
|
||||||
|
@ -113,6 +115,28 @@ def put_cleaned_data_in_dict(dict, form):
|
||||||
dict[field] = form.cleaned_data[field]
|
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
|
# Account views
|
||||||
# -----
|
# -----
|
||||||
|
|
Loading…
Reference in a new issue