aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--forms.py20
1 files changed, 18 insertions, 2 deletions
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 <http://www.gnu.org/licenses/>.
+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")