Projet

Général

Profil

« Précédent | Suivant » 

Révision 8c0910ce

Ajouté par Serghei Mihai il y a presque 10 ans

agenda: allow empty time and duration for events of type "TELEPHONE" and "COURRIEL"

Closes #5015

Voir les différences:

calebasse/agenda/appointments.py
6 6
from interval import Interval, IntervalSet
7 7

  
8 8
from calebasse.actes.validation_states import VALIDATION_STATES
9
from .models import EventWithAct
9 10

  
10 11
class Appointment(object):
11 12

  
......
36 37
        self.validation = None
37 38
        self.holiday = False
38 39
        self.services_names = []
40
        self.event = False
39 41
        self.__set_time(begin_time)
40 42

  
41 43
    def __set_time(self, time):
......
47 49

  
48 50
    def init_from_event(self, event, service, validation_states=None):
49 51
        delta = event.end_datetime - event.start_datetime
52
        self.event = isinstance(event, EventWithAct)
50 53
        self.event_id = event.id
51 54
        self.length = delta.seconds / 60
52 55
        self.title = event.title
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
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']

Formats disponibles : Unified diff