From a2fcd4c7c42b6c02ff8ff7dac4aa23b3d17407de Mon Sep 17 00:00:00 2001
From: Alban Gruin
Date: Wed, 17 Jan 2018 12:34:11 +0100
Subject: Base du formulaire de QSJPS
---
forms.py | 21 +++++++++++++++++++++
1 file changed, 21 insertions(+)
create mode 100644 forms.py
(limited to 'forms.py')
diff --git a/forms.py b/forms.py
new file mode 100644
index 0000000..34081c0
--- /dev/null
+++ b/forms.py
@@ -0,0 +1,21 @@
+# Copyright (C) 2018 Alban Gruin
+#
+# celcatsanitizer is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published
+# by the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# celcatsanitizer is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with celcatsanitizer. If not, see .
+
+from django import forms
+
+
+class QSJPSForm(forms.Form):
+ begin = forms.DateTimeField(label="Début")
+ end = forms.DateTimeField(label="Fin")
--
cgit v1.2.1
From d2a52ee6844d363ae020a49781b46402d7717a27 Mon Sep 17 00:00:00 2001
From: Alban Gruin
Date: Wed, 17 Jan 2018 16:09:28 +0100
Subject: Ajout d’un champ jour au formulaire qsjps
Valeurs par défaut des champs du formulaire
Format de validation
---
forms.py | 20 ++++++++++++++++++--
1 file changed, 18 insertions(+), 2 deletions(-)
(limited to 'forms.py')
diff --git a/forms.py b/forms.py
index 34081c0..d886dbf 100644
--- a/forms.py
+++ b/forms.py
@@ -13,9 +13,25 @@
# You should have received a copy of the GNU Affero General Public License
# along with celcatsanitizer. If not, see .
+from datetime import timedelta
from django import forms
+from .utils import tz_now
+
class QSJPSForm(forms.Form):
- begin = forms.DateTimeField(label="Début")
- end = forms.DateTimeField(label="Fin")
+ day = forms.DateField(label="Jour")
+
+ # Ces champs n’acceptent pas les secondes
+ begin = forms.TimeField(label="Heure de début", input_formats=("%H:%M",))
+ end = forms.TimeField(label="Heure de fin", input_formats=("%H:%M",))
+
+ def __init__(self, *args, **kwargs):
+ super(QSJPSForm, self).__init__(*args, **kwargs)
+
+ # On définit les valeurs par défaut de cette manière pour
+ # éviter les mauvaises surprises. On retire les secondes des
+ # heures de début et de fin.
+ self.fields["day"].initial = tz_now()
+ self.fields["begin"].initial = tz_now().strftime("%H:%M")
+ self.fields["end"].initial = (tz_now() + timedelta(hours=1)).strftime("%H:%M")
--
cgit v1.2.1
From 97f62a20f1716a9915358959b2e25912e8b17a90 Mon Sep 17 00:00:00 2001
From: Alban Gruin
Date: Wed, 17 Jan 2018 16:50:08 +0100
Subject: Utilisation des champs de formulaires date et time à la place de text
---
forms.py | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
(limited to 'forms.py')
diff --git a/forms.py b/forms.py
index d886dbf..0d823eb 100644
--- a/forms.py
+++ b/forms.py
@@ -14,17 +14,21 @@
# along with celcatsanitizer. If not, see .
from datetime import timedelta
+
from django import forms
+from django.forms.widgets import DateInput, TimeInput
from .utils import tz_now
class QSJPSForm(forms.Form):
- day = forms.DateField(label="Jour")
+ day = forms.DateField(label="Jour", widget=DateInput(attrs={"type": "date"}))
# Ces champs n’acceptent pas les secondes
- begin = forms.TimeField(label="Heure de début", input_formats=("%H:%M",))
- end = forms.TimeField(label="Heure de fin", input_formats=("%H:%M",))
+ begin = forms.TimeField(label="Heure de début", input_formats=("%H:%M",),
+ widget=TimeInput(attrs={"type": "time"}))
+ end = forms.TimeField(label="Heure de fin", input_formats=("%H:%M",),
+ widget=TimeInput(attrs={"type": "time"}))
def __init__(self, *args, **kwargs):
super(QSJPSForm, self).__init__(*args, **kwargs)
--
cgit v1.2.1
From 8418b6b82e892a435b16f2be90ae94bb7961416b Mon Sep 17 00:00:00 2001
From: Alban Gruin
Date: Wed, 17 Jan 2018 21:19:15 +0100
Subject: Validation du formulaire
---
forms.py | 14 ++++++++++++++
1 file changed, 14 insertions(+)
(limited to 'forms.py')
diff --git a/forms.py b/forms.py
index 0d823eb..fbd6d02 100644
--- a/forms.py
+++ b/forms.py
@@ -39,3 +39,17 @@ class QSJPSForm(forms.Form):
self.fields["day"].initial = tz_now()
self.fields["begin"].initial = tz_now().strftime("%H:%M")
self.fields["end"].initial = (tz_now() + timedelta(hours=1)).strftime("%H:%M")
+
+ def clean(self):
+ form_data = self.cleaned_data
+
+ # On vérifie que les valeurs de début et de fin sont correctes
+ # (si ce n’est pas le cas, elles ne se trouvent pas dans le
+ # dictionnaire), et, le cas échéant, on vérifie que l’heure de
+ # début est strictement inférieure à l’heure de fin.
+ if "begin" in form_data and "end" in form_data and \
+ form_data["begin"] >= form_data["end"]:
+ # Si l’heure de fin est plus petite ou égale, on affiche
+ # une erreur.
+ self._errors["end"].append("L’heure de début doit être supérieure à celle de fin.")
+ return form_data
--
cgit v1.2.1
From 85112aafbcfe684b8b4d4fa2a47fd6cc2dcd2e25 Mon Sep 17 00:00:00 2001
From: Alban Gruin
Date: Wed, 17 Jan 2018 19:15:09 +0100
Subject: Format correct de la date
---
forms.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'forms.py')
diff --git a/forms.py b/forms.py
index fbd6d02..5e76bc1 100644
--- a/forms.py
+++ b/forms.py
@@ -36,7 +36,7 @@ class QSJPSForm(forms.Form):
# On définit les valeurs par défaut de cette manière pour
# éviter les mauvaises surprises. On retire les secondes des
# heures de début et de fin.
- self.fields["day"].initial = tz_now()
+ self.fields["day"].initial = tz_now().strftime("%Y-%m-%d")
self.fields["begin"].initial = tz_now().strftime("%H:%M")
self.fields["end"].initial = (tz_now() + timedelta(hours=1)).strftime("%H:%M")
--
cgit v1.2.1
From c9388e29b2f9ee18a9e190683a8a33fb710684c5 Mon Sep 17 00:00:00 2001
From: Alban Gruin
Date: Sat, 27 Jan 2018 17:56:45 +0100
Subject: PEP8
---
forms.py | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
(limited to 'forms.py')
diff --git a/forms.py b/forms.py
index 5e76bc1..00dbf9e 100644
--- a/forms.py
+++ b/forms.py
@@ -22,7 +22,8 @@ from .utils import tz_now
class QSJPSForm(forms.Form):
- day = forms.DateField(label="Jour", widget=DateInput(attrs={"type": "date"}))
+ day = forms.DateField(label="Jour",
+ widget=DateInput(attrs={"type": "date"}))
# Ces champs n’acceptent pas les secondes
begin = forms.TimeField(label="Heure de début", input_formats=("%H:%M",),
@@ -38,7 +39,8 @@ class QSJPSForm(forms.Form):
# heures de début et de fin.
self.fields["day"].initial = tz_now().strftime("%Y-%m-%d")
self.fields["begin"].initial = tz_now().strftime("%H:%M")
- self.fields["end"].initial = (tz_now() + timedelta(hours=1)).strftime("%H:%M")
+ self.fields["end"].initial = (tz_now() + timedelta(hours=1)) \
+ .strftime("%H:%M")
def clean(self):
form_data = self.cleaned_data
@@ -51,5 +53,6 @@ class QSJPSForm(forms.Form):
form_data["begin"] >= form_data["end"]:
# Si l’heure de fin est plus petite ou égale, on affiche
# une erreur.
- self._errors["end"].append("L’heure de début doit être supérieure à celle de fin.")
+ self._errors["end"].append("L’heure de début doit être supérieure "
+ "à celle de fin.")
return form_data
--
cgit v1.2.1