Project

General

Profile

« Previous | Next » 

Revision 5f372104

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

Agenda: add appointments management

  • agenda/appointments.py: add a class to display appointments
  • agenda/managers.py: add serives maangement to OccurtenceManager
  • agenda/views.py: small fix
  • personnes/models.py: cosmetic

View differences:

calebasse/agenda/appointments.py
from calebasse.agenda.models import Occurence
from calebasse.personnes.models import TimeTable
class Appointment(object):
def __init__(self, title=None, begin_hour=None, type=None,
length=None, description=None, room=None, convocation_sent=None,
service_name=None):
""" """
self.title = title
self.begin_hour = begin_hour
self.type = type
self.length = length
self.description = description
self.room = room
self.convocation_sent = None
self.service_name = None
def load_from_occurence(self, occurence, service):
""" """
delta = occurence.end_time - occurence.start_time
self.length = (delta.hours * 60) + dela.minutes
self.title = occurence.title
self.begin_hour = occurence.start_time.hours
if service in occurence.services:
self.type = "busy-here"
else:
self.type = "busy-elsewhere"
self.service_name = service.name
self.room = occurence.room.name
self.convocation_sent = occurence.convocation_sent
self.description = occurence.description
def get_daily_appointments(date, worker, service):
"""
"""
weekday_mapping = {
'0': 'dimanche',
'1': 'lundi',
'2': 'mardi',
'3': 'mercredi',
'4': 'jeudi',
'5': 'vendredi'
'6': 'samedi'
}
weekday = weekday_mapping[date.strftime("%w")]
time_tables = TimeTable.objects.filter(worker=worker).\
filter(service=service).\
filter(weekday=weekday).\
filter(start_date__lte=date).\
filter(end_date__gte=date)
occurences = Occurence.objects.daily_occurrences(date, [worker])
calebasse/agenda/managers.py
#use_for_related_fields = True
def daily_occurrences(self, date=None, participants=None):
def daily_occurrences(self, date, participants=None, services=None):
'''
Returns a queryset of for instances that have any overlap with a
particular day.
......
)
if participants:
return qs.filter(event__participants__in=participants)
else:
return qs
qs = qs.filter(event__participants__in=participants)
if services:
qs = qs.filter(services__in=services)
return qs
def daily_disponiblity(self, date, participants):
start_datetime = datetime(date.year, date.month, date.day, 8, 0)
calebasse/agenda/views.py
context['workers_agenda'].append({'worker': worker,
'agenda': Occurrence.objects.daily_occurrences(context['date'], [worker])})
context['disponnibility'] = Occurrence.objects.daily_disponiblity(context['date'], context['workers'])
context['disponnibility'] = Occurrence.objects.daily_disponiblity(context['date'], workers)
return context
calebasse/personnes/models.py
return self.filter(services__in=[service]).filter(type=type)
else:
return self.filter(services__in=[service])
class Worker(People):
objects = WorkerManager()

Also available in: Unified diff