0001-agenda-allow-empty-time-and-duration-for-events-of-t.patch
calebasse/agenda/forms.py | ||
---|---|---|
1 | 1 |
# -*- coding: utf-8 -*- |
2 | 2 | |
3 |
from datetime import datetime, timedelta |
|
3 |
from datetime import datetime, timedelta, time
|
|
4 | 4 | |
5 | 5 |
from django import forms |
6 | 6 | |
... | ... | |
48 | 48 |
super(NewAppointmentForm, self).__init__(instance=instance, **kwargs) |
49 | 49 |
self.fields['date'].css = 'datepicker' |
50 | 50 |
self.fields['participants'].required = True |
51 |
self.fields['time'].required = False |
|
52 |
self.fields['duration'].required = False |
|
51 | 53 |
if service: |
52 | 54 |
self.service = service |
53 | 55 |
self.fields['participants'].queryset = \ |
... | ... | |
58 | 60 |
ActType.objects.for_service(service) \ |
59 | 61 |
.order_by('name') |
60 | 62 | |
63 |
def clean_time(self): |
|
64 |
act_type = self.data.get('act_type') |
|
65 |
# act type is available as raw data from the post request |
|
66 |
# 213 - COURRIEL |
|
67 |
# 99 - TELEPHONE |
|
68 |
if act_type in ('213', '99'): |
|
69 |
return time(8, 0) |
|
70 |
if self.cleaned_data['time']: |
|
71 |
return self.cleaned_data['time'] |
|
72 |
raise forms.ValidationError(u'Veuillez saisir une heure') |
|
73 | ||
74 | ||
61 | 75 |
def clean_duration(self): |
76 |
act_type = self.data.get('act_type') |
|
77 |
if act_type in ('213', '99'): |
|
78 |
return 10 |
|
62 | 79 |
duration = self.cleaned_data['duration'] |
63 | 80 |
try: |
64 | 81 |
return int(duration) |
65 |
- |