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)
|
Fix #1842: daily disponnibility add away state