From a14fcc0191850b8eb8e139392031d0026e947853 Mon Sep 17 00:00:00 2001 From: Serghei MIHAI Date: Wed, 16 Jul 2014 11:09:37 +0200 Subject: [PATCH] agenda: allow empty time and duration for events of type "TELEPHONE" and "COURRIEL" Closes #5015 --- calebasse/agenda/forms.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/calebasse/agenda/forms.py b/calebasse/agenda/forms.py index 73a946b..658f3ff 100644 --- a/calebasse/agenda/forms.py +++ b/calebasse/agenda/forms.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -from datetime import datetime, timedelta +from datetime import datetime, timedelta, time from django import forms @@ -48,6 +48,8 @@ class NewAppointmentForm(BaseForm): super(NewAppointmentForm, self).__init__(instance=instance, **kwargs) self.fields['date'].css = 'datepicker' self.fields['participants'].required = True + self.fields['time'].required = False + self.fields['duration'].required = False if service: self.service = service self.fields['participants'].queryset = \ @@ -58,7 +60,22 @@ class NewAppointmentForm(BaseForm): ActType.objects.for_service(service) \ .order_by('name') + def clean_time(self): + act_type = self.data.get('act_type') + # act type is available as raw data from the post request + # 213 - COURRIEL + # 99 - TELEPHONE + if act_type in ('213', '99'): + return time(8, 0) + if self.cleaned_data['time']: + return self.cleaned_data['time'] + raise forms.ValidationError(u'Veuillez saisir une heure') + + def clean_duration(self): + act_type = self.data.get('act_type') + if act_type in ('213', '99'): + return 10 duration = self.cleaned_data['duration'] try: return int(duration) -- 2.0.1