Project

General

Profile

« Previous | Next » 

Revision d8468991

Added by Jérôme Schneider over 12 years ago

Fix #1842: daily disponnibility add away state

View differences:

calebasse/agenda/managers.py
7 7
from model_utils.managers import InheritanceManager
8 8

  
9 9
from calebasse.agenda.conf import default
10
from calebasse.personnes.models import TimeTable
10 11
from calebasse.exceptions import CalebasseException
11 12
from calebasse import agenda
12 13

  
......
119 120
            qs = qs.filter(event__event_type=event_type)
120 121
        return qs
121 122

  
122
    def daily_disponiblity(self, date, occurrences, participants):
123
    def daily_disponiblity(self, date, occurrences, participants, time_tables):
123 124
        result = dict()
124 125
        quater = 0
125 126
        occurrences_set = {}
127
        timetables_set = {}
126 128
        for participant in participants:
127 129
            occurrences_set[participant.id] = IntervalSet((o.to_interval() for o in occurrences[participant.id]))
130
            timetables_set[participant.id] = IntervalSet((t.to_interval(date) for t in time_tables[participant.id]))
128 131
        start_datetime = datetime(date.year, date.month, date.day, 8, 0)
129 132
        end_datetime = datetime(date.year, date.month, date.day, 8, 15)
130 133
        while (start_datetime.hour <= 19):
......
138 141
                    quater = 0
139 142

  
140 143
                interval = IntervalSet.between(start_datetime, end_datetime)
141
                delta = interval - occurrences_set[participant.id]
142
                if delta and delta[0].upper_bound == interval[0].upper_bound and \
143
                        delta[0].lower_bound and interval[0].upper_bound :
144
                    result[start_datetime.hour][quater].append({'id': participant.id, 'dispo': 'free'})
145
                else:
144
                if interval.issubset(occurrences_set[participant.id]):
146 145
                    result[start_datetime.hour][quater].append({'id': participant.id, 'dispo': 'busy'})
146
                elif not interval.issubset(timetables_set[participant.id]):
147
                    result[start_datetime.hour][quater].append({'id': participant.id, 'dispo': 'away'})
148
                else:
149
                    result[start_datetime.hour][quater].append({'id': participant.id, 'dispo': 'free'})
147 150
            quater += 1
148 151
            start_datetime += timedelta(minutes=15)
149 152
            end_datetime += timedelta(minutes=15)
calebasse/agenda/views.py
54 54
            workers.extend(data['workers'])
55 55

  
56 56
        occurrences_workers = {}
57
        time_tables_workers = {}
57 58
        for worker in workers:
58 59
            time_tables_worker = [tt for tt in time_tables if tt.worker.id == worker.id]
59 60
            occurrences_worker = [o for o in occurrences if worker.id in o.event.participants.values_list('id', flat=True)]
60 61
            occurrences_workers[worker.id] = occurrences_worker
62
            time_tables_workers[worker.id] = time_tables_worker
61 63
            context['workers_agenda'].append({'worker': worker,
62 64
                    'appointments': get_daily_appointments(context['date'], worker, self.service,
63 65
                        time_tables_worker, occurrences_worker)})
64 66

  
65 67
        context['disponibility'] = Occurrence.objects.daily_disponiblity(context['date'],
66
                occurrences_workers, workers)
68
                occurrences_workers, workers, time_tables_workers)
67 69
        return context
68 70

  
69 71
class AgendaServiceActivityView(TemplateView):

Also available in: Unified diff