Projet

Général

Profil

0001-agenda-allow-empty-time-and-duration-for-events-of-t.patch

Serghei Mihai (congés, retour 15/05), 16 juillet 2014 12:38

Télécharger (3,18 ko)

Voir les différences:

Subject: [PATCH] agenda: allow empty time and duration for events of type
 "TELEPHONE" and "COURRIEL"

Closes #5015
 calebasse/agenda/forms.py | 37 +++++++++++++++++++++++++++++++------
 1 file changed, 31 insertions(+), 6 deletions(-)
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
from django.db.models import Q
6 7

  
7 8
from ..dossiers.models import PatientRecord
8 9
from ..personnes.models import Worker
......
48 49
        super(NewAppointmentForm, self).__init__(instance=instance, **kwargs)
49 50
        self.fields['date'].css = 'datepicker'
50 51
        self.fields['participants'].required = True
52
        self.fields['time'].required = False
53
        self.fields['duration'].required = False
51 54
        if service:
52 55
            self.service = service
56
            self.special_types = [str(act.id) for act in ActType.objects.for_service(self.service).filter(Q(name__iexact='courriel')
57
                                                                                                          | Q(name__iexact='telephone')
58
                                                                                                          | Q(name__iexact='téléphone'))]
53 59
            self.fields['participants'].queryset = \
54 60
                    Worker.objects.for_service(service)
55 61
            self.fields['patient'].queryset = \
......
58 64
                    ActType.objects.for_service(service) \
59 65
                    .order_by('name')
60 66

  
67
    def clean_time(self):
68
        act_type = self.data.get('act_type')
69
        # act type is available as raw data from the post request
70
        if act_type in self.special_types:
71
            return time(8, 0)
72
        if self.cleaned_data['time']:
73
            return self.cleaned_data['time']
74
        raise forms.ValidationError('Ce champs est obligatoire')
75

  
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

  
82
        if self.cleaned_data['duration']:
83
            duration = self.cleaned_data['duration']
84
            try:
85
                duration = int(duration)
86
                if duration <= 0:
87
                    raise forms.ValidationError('Le champ doit contenir un chiffre positif')
88
                return duration
89
            except ValueError:
90
                raise forms.ValidationError('Le champ doit contenir un chiffre')
91
        raise forms.ValidationError('Ce champs est obligatoire')
67 92

  
68 93
    def clean_patient(self):
69 94
        patients = self.cleaned_data['patient']
70
-