Project

General

Profile

Download (2.32 KB) Statistics
| Branch: | Tag: | Revision:
import datetime

from django.shortcuts import redirect

from calebasse.cbv import TemplateView, CreateView
from calebasse.agenda.models import Occurrence
from calebasse.actes.models import EventAct
from calebasse.agenda.appointments import get_daily_appointments
from calebasse.personnes.models import Worker
from calebasse.ressources.models import Service, WorkerType

from forms import NewAppointmentForm

def redirect_today(request, service):
'''If not date is given we redirect on the agenda for today'''
return redirect('agenda', date=datetime.date.today().strftime('%Y-%m-%d'),
service=service)

class AgendaHomepageView(TemplateView):

template_name = 'agenda/index.html'

def get_context_data(self, **kwargs):
context = super(AgendaHomepageView, self).get_context_data(**kwargs)
context['workers_types'] = []
context['workers_agenda'] = []
context['disponnibility'] = {}
workers = []
service = Service.objects.get(name=context['service_name'])
for worker_type in WorkerType.objects.all():
data = {'type': worker_type.name, 'workers': Worker.objects.for_service(self.service, worker_type) }
context['workers_types'].append(data)
workers.extend(data['workers'])

for worker in workers:
context['workers_agenda'].append({'worker': worker,
'appointments': get_daily_appointments(context['date'], worker, service)})

context['disponibility'] = Occurrence.objects.daily_disponiblity(context['date'], workers)
return context

class NewAppointmentView(CreateView):
model = EventAct
form_class = NewAppointmentForm
template_name = 'agenda/nouveau-rdv.html'
success_url = '..'

def get_initial(self):
initial = super(NewAppointmentView, self).get_initial()
initial['date'] = self.kwargs.get('date')
initial['participants'] = self.request.GET.getlist('participants')
initial['time'] = self.request.GET.get('time')
return initial

def get_form_kwargs(self):
kwargs = super(NewAppointmentView, self).get_form_kwargs()
kwargs['service'] = self.service
return kwargs

def post(self, *args, **kwargs):
return super(NewAppointmentView, self).post(*args, **kwargs)

def new_appointment(request):
pass
(10-10/10)