parent
6fdbe2459b
commit
7d4712a3f4
|
@ -49,7 +49,7 @@ class EventQuerySet(InheritanceQuerySet):
|
|||
occurences = ( e.today_occurrence(today) for e in self )
|
||||
return sorted(occurences, key=lambda e: e.start_datetime)
|
||||
|
||||
def daily_disponibilities(self, date, events, participants, time_tables,
|
||||
def daily_disponibilities(self, date, events, participant, time_tables,
|
||||
holidays):
|
||||
'''Slice the day into quarters between 8:00 and 19:00, and returns the
|
||||
list of particpants with their status amon free, busy and away for each
|
||||
|
@ -63,30 +63,32 @@ class EventQuerySet(InheritanceQuerySet):
|
|||
'''
|
||||
result = dict()
|
||||
quarter = 0
|
||||
events_set = {}
|
||||
timetables_set = {}
|
||||
holidays_set = {}
|
||||
for participant in participants:
|
||||
events_set[participant.id] = IntervalSet((o.to_interval() for o in events[participant.id] if not o.is_event_absence()))
|
||||
timetables_set[participant.id] = IntervalSet((t.to_interval(date) for t in time_tables[participant.id]))
|
||||
holidays_set[participant.id] = IntervalSet((h.to_interval(date) for h in holidays[participant.id]))
|
||||
|
||||
events_intervals = IntervalSet((o.to_interval() for o in events if not o.is_event_absence()))
|
||||
|
||||
timetables_intervals = IntervalSet((t.to_interval(date) for t in time_tables))
|
||||
holidays_intervals = IntervalSet((h.to_interval(date) for h in holidays))
|
||||
|
||||
start_datetime = datetime(date.year, date.month, date.day, 8, 0)
|
||||
end_datetime = datetime(date.year, date.month, date.day, 8, 15)
|
||||
while (start_datetime.hour <= 19):
|
||||
for participant in participants:
|
||||
if not result.has_key(start_datetime.hour):
|
||||
result[start_datetime.hour] = [[], [], [], []]
|
||||
quarter = 0
|
||||
interval = IntervalSet.between(start_datetime, end_datetime, False)
|
||||
mins = quarter * 15
|
||||
if interval.intersection(events_set[participant.id]):
|
||||
result[start_datetime.hour][quarter].append((mins, {'id': participant.id, 'dispo': 'busy'}))
|
||||
elif interval.intersection(holidays_set[participant.id]):
|
||||
result[start_datetime.hour][quarter].append((mins, {'id': participant.id, 'dispo': 'busy'}))
|
||||
elif not interval.intersection(timetables_set[participant.id]):
|
||||
result[start_datetime.hour][quarter].append((mins, {'id': participant.id, 'dispo': 'away'}))
|
||||
else:
|
||||
result[start_datetime.hour][quarter].append((mins, {'id': participant.id, 'dispo': 'free'}))
|
||||
|
||||
if not result.has_key(start_datetime.hour):
|
||||
result[start_datetime.hour] = [[], [], [], []]
|
||||
quarter = 0
|
||||
interval = IntervalSet.between(start_datetime, end_datetime, False)
|
||||
mins = quarter * 15
|
||||
crossed_events = filter(lambda e: e.start_datetime <= start_datetime and e.end_datetime >= end_datetime, events)
|
||||
if len(crossed_events) > 1:
|
||||
result[start_datetime.hour][quarter].append((mins, {'id': participant.id, 'dispo': 'common'}))
|
||||
elif interval.intersection(events_intervals):
|
||||
result[start_datetime.hour][quarter].append((mins, {'id': participant.id, 'dispo': 'busy'}))
|
||||
elif interval.intersection(holidays_intervals):
|
||||
result[start_datetime.hour][quarter].append((mins, {'id': participant.id, 'dispo': 'busy'}))
|
||||
elif not interval.intersection(timetables_intervals):
|
||||
result[start_datetime.hour][quarter].append((mins, {'id': participant.id, 'dispo': 'away'}))
|
||||
else:
|
||||
result[start_datetime.hour][quarter].append((mins, {'id': participant.id, 'dispo': 'free'}))
|
||||
quarter += 1
|
||||
start_datetime += timedelta(minutes=15)
|
||||
end_datetime += timedelta(minutes=15)
|
||||
|
|
|
@ -632,7 +632,9 @@ class AjaxDisponibilityColumnView(TemplateView):
|
|||
for event in events:
|
||||
if event.start_datetime <= start_datetime and event.end_datetime >= end_datetime:
|
||||
dispo = 'busy'
|
||||
|
||||
crossed_events = filter(lambda e: e.start_datetime <= start_datetime and e.end_datetime >= end_datetime, events)
|
||||
if len(crossed_events) > 1:
|
||||
dispo = 'common'
|
||||
disponibility[start_datetime.hour][quarter].append((mins, {'id': ressource_id, 'dispo': dispo}))
|
||||
quarter += 1
|
||||
start_datetime += datetime.timedelta(minutes=15)
|
||||
|
@ -645,11 +647,11 @@ class AjaxDisponibilityColumnView(TemplateView):
|
|||
def get_worker_context_data(self, worker_id, context):
|
||||
worker = Worker.objects.get(pk=worker_id)
|
||||
|
||||
time_tables_worker = TimeTable.objects.select_related('worker'). \
|
||||
time_tables = TimeTable.objects.select_related('worker'). \
|
||||
filter(services=self.service, worker=worker). \
|
||||
for_today(self.date). \
|
||||
order_by('start_date')
|
||||
holidays_worker = Holiday.objects.for_worker(worker). \
|
||||
holidays = Holiday.objects.for_worker(worker). \
|
||||
for_period(self.date, self.date). \
|
||||
order_by('start_date')
|
||||
events = Event.objects.for_today(self.date) \
|
||||
|
@ -667,13 +669,13 @@ class AjaxDisponibilityColumnView(TemplateView):
|
|||
|
||||
events = list(events) + list(eventswithact)
|
||||
events = [ e.today_occurrence(self.date) for e in events ]
|
||||
time_tables_workers = {worker.id: time_tables_worker}
|
||||
time_tables_workers = {worker.id: time_tables}
|
||||
events_workers = {worker.id: events}
|
||||
holidays_workers = {worker.id: holidays_worker}
|
||||
holidays_workers = {worker.id: holidays}
|
||||
|
||||
context['initials'] = worker.initials
|
||||
context['disponibility'] = Event.objects.daily_disponibilities(self.date,
|
||||
events_workers, [worker], time_tables_workers, holidays_workers)
|
||||
events, worker, time_tables, holidays)
|
||||
return context
|
||||
|
||||
def get_context_data(self, ressource_type, ressource_id, **kwargs):
|
||||
|
|
|
@ -178,6 +178,10 @@ li.away {
|
|||
background: #ccc;
|
||||
}
|
||||
|
||||
li.common {
|
||||
background: #d500a5;
|
||||
}
|
||||
|
||||
li#time {
|
||||
margin-top: -0.15em;
|
||||
}
|
||||
|
|
Reference in New Issue