Project

General

Profile

« Previous | Next » 

Revision 1eab6c73

Added by Frédéric Péters over 13 years ago

agenda: display personal holidays (#2038)

View differences:

calebasse/agenda/appointments.py
self.length = length
self.__set_time(begin_time)
def init_busy_time(self, title, length, begin_time):
self.title = title
self.type = "busy-here"
self.length = length
self.__set_time(begin_time)
def init_start_stop(self, title, time):
"""
......
self.title = title
self.__set_time(time)
def get_daily_appointments(date, worker, service, time_tables, occurrences):
def get_daily_appointments(date, worker, service, time_tables, occurrences, holidays):
"""
"""
appointments = []
timetables_set = IntervalSet((t.to_interval(date) for t in time_tables))
occurrences_set = IntervalSet((o.to_interval() for o in occurrences))
for free_time in timetables_set - occurrences_set:
holidays_set = IntervalSet((h.to_interval(date) for h in holidays))
for free_time in timetables_set - (occurrences_set+holidays_set):
if free_time:
delta = free_time.upper_bound - free_time.lower_bound
delta_minutes = delta.seconds / 60
......
appointment = Appointment()
appointment.init_from_occurrence(occurrence, service)
appointments.append(appointment)
for holiday in holidays:
interval = holiday.to_interval(date)
delta = interval.upper_bound - interval.lower_bound
delta_minutes = delta.seconds / 60
appointment = Appointment()
appointment.init_busy_time(u"Congé",
delta_minutes,
time(interval.lower_bound.hour, interval.lower_bound.minute))
appointments.append(appointment)
for time_table in time_tables:
interval_set = IntervalSet.between(time_table.to_interval(date).lower_bound.time(),
time_table.to_interval(date).upper_bound.time())
for holiday in holidays:
holiday_interval_set = IntervalSet.between(holiday.to_interval(date).lower_bound.time(),
holiday.to_interval(date).upper_bound.time())
interval_set = interval_set - holiday_interval_set
if not interval_set:
continue
start_time = interval_set.lower_bound()
end_time = interval_set.upper_bound()
appointment = Appointment()
appointment.init_start_stop(u"Arrivée",
time(time_table.start_time.hour, time_table.start_time.minute))
appointment.init_start_stop(u"Arrivée", start_time)
appointment.weight = -1
appointments.append(appointment)
appointment = Appointment()
appointment.init_start_stop(u"Départ",
time(time_table.end_time.hour, time_table.end_time.minute))
appointment.init_start_stop(u"Départ", end_time)
appointment.weight = 1
appointments.append(appointment)
calebasse/agenda/managers.py
qs = qs.filter(event__event_type=event_type)
return qs
def daily_disponiblity(self, date, occurrences, participants, time_tables):
def daily_disponiblity(self, date, occurrences, participants, time_tables, holidays):
result = dict()
quater = 0
occurrences_set = {}
timetables_set = {}
holidays_set = {}
for participant in participants:
occurrences_set[participant.id] = IntervalSet((o.to_interval() for o in occurrences[participant.id]))
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]))
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):
......
interval = IntervalSet.between(start_datetime, end_datetime, False)
if interval.intersection(occurrences_set[participant.id]):
result[start_datetime.hour][quater].append({'id': participant.id, 'dispo': 'busy'})
elif interval.intersection(holidays_set[participant.id]):
result[start_datetime.hour][quater].append({'id': participant.id, 'dispo': 'busy'})
elif not interval.intersection(timetables_set[participant.id]):
result[start_datetime.hour][quater].append({'id': participant.id, 'dispo': 'away'})
else:
calebasse/agenda/views.py
from calebasse.cbv import TemplateView, CreateView, UpdateView
from calebasse.agenda.models import Occurrence, Event, EventType
from calebasse.personnes.models import TimeTable
from calebasse.personnes.models import TimeTable, Holiday
from calebasse.actes.models import EventAct
from calebasse.agenda.appointments import get_daily_appointments
from calebasse.personnes.models import Worker
......
filter(services=self.service). \
for_today(self.date). \
order_by('start_date')
holidays = Holiday.objects.select_related('worker'). \
for_period(self.date, self.date). \
order_by('start_date')
occurrences = Occurrence.objects.daily_occurrences(context['date']).order_by('start_time')
context['workers_types'] = []
......
occurrences_workers = {}
time_tables_workers = {}
holidays_workers = {}
for worker in workers:
time_tables_worker = [tt for tt in time_tables if tt.worker.id == worker.id]
occurrences_worker = [o for o in occurrences if worker.id in o.event.participants.values_list('id', flat=True)]
holidays_worker = [h for h in holidays if h.worker_id == worker.id]
occurrences_workers[worker.id] = occurrences_worker
time_tables_workers[worker.id] = time_tables_worker
holidays_workers[worker.id] = holidays_worker
context['workers_agenda'].append({'worker': worker,
'appointments': get_daily_appointments(context['date'], worker, self.service,
time_tables_worker, occurrences_worker)})
time_tables_worker, occurrences_worker, holidays_worker)})
context['disponibility'] = Occurrence.objects.daily_disponiblity(context['date'],
occurrences_workers, workers, time_tables_workers)
occurrences_workers, workers, time_tables_workers, holidays_workers)
return context
class AgendaServiceActivityView(TemplateView):
calebasse/personnes/models.py
# -*- coding: utf-8 -*-
from datetime import datetime, date
from datetime import datetime, date, time as datetime_time
from django.db import models
from django.db.models import query
......
date_filter(self.end_date, 'j F Y'))
return ret
def to_interval(self, date):
if date == self.start_date:
start_time = self.start_time or datetime_time(8, 0)
else:
start_time = datetime_time(8, 0)
if date == self.end_date:
end_time = self.end_time or datetime_time(20, 0)
else:
end_time = datetime_time(20, 0)
return Interval(datetime.combine(self.start_date, start_time),
datetime.combine(self.end_date, end_time))
class ExternalDoctor(People):
class Meta:
verbose_name = u'Médecin extérieur'

Also available in: Unified diff