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 |
from django.db.models import Q
|
|
7 |
from django.utils.translation import ugettext_lazy as _
|
6 |
8 |
|
7 |
9 |
from ..dossiers.models import PatientRecord
|
8 |
10 |
from ..personnes.models import Worker
|
... | ... | |
48 |
50 |
super(NewAppointmentForm, self).__init__(instance=instance, **kwargs)
|
49 |
51 |
self.fields['date'].css = 'datepicker'
|
50 |
52 |
self.fields['participants'].required = True
|
|
53 |
self.fields['time'].required = False
|
|
54 |
self.fields['duration'].required = False
|
51 |
55 |
if service:
|
52 |
56 |
self.service = service
|
|
57 |
self.special_types = [str(act.id) for act in ActType.objects.filter(Q(name__iexact='courriel')
|
|
58 |
| Q(name__iexact='telephone')
|
|
59 |
| Q(name__iexact='téléphone'))]
|
53 |
60 |
self.fields['participants'].queryset = \
|
54 |
61 |
Worker.objects.for_service(service)
|
55 |
62 |
self.fields['patient'].queryset = \
|
... | ... | |
58 |
65 |
ActType.objects.for_service(service) \
|
59 |
66 |
.order_by('name')
|
60 |
67 |
|
|
68 |
def clean_time(self):
|
|
69 |
act_type = self.data.get('act_type')
|
|
70 |
# act type is available as raw data from the post request
|
|
71 |
if act_type in self.special_types:
|
|
72 |
return time(8, 0)
|
|
73 |
if self.cleaned_data['time']:
|
|
74 |
return self.cleaned_data['time']
|
|
75 |
raise forms.ValidationError(_(u'This field is required.'))
|
|
76 |
|
61 |
77 |
def clean_duration(self):
|
62 |
|
duration = self.cleaned_data['duration']
|
63 |
|
try:
|
64 |
|
return int(duration)
|
65 |
|
except ValueError:
|
66 |
|
raise forms.ValidationError('Veuillez saisir un entier')
|
|
78 |
act_type = self.data.get('act_type')
|
|
79 |
if act_type in self.special_types:
|
|
80 |
return 10
|
|
81 |
if self.cleaned_data['duration']:
|
|
82 |
duration = self.cleaned_data['duration']
|
|
83 |
try:
|
|
84 |
duration = int(duration)
|
|
85 |
if duration <= 0:
|
|
86 |
raise ValueError
|
|
87 |
return duration
|
|
88 |
except ValueError:
|
|
89 |
raise forms.ValidationError(u'Le champ doit contenir uniquement des chiffres')
|
|
90 |
raise forms.ValidationError(_(u'This field is required.'))
|
67 |
91 |
|
68 |
92 |
def clean_patient(self):
|
69 |
93 |
patients = self.cleaned_data['patient']
|
agenda: allow empty time and duration for events of type "TELEPHONE" and "COURRIEL"
Closes #5015