Project

General

Profile

Download (1.47 KB) Statistics
| Branch: | Tag: | Revision:

calebasse / calebasse / agenda / views.py @ 6b76bceb

1
import datetime
2

    
3
from django.shortcuts import redirect
4

    
5
from calebasse.cbv import TemplateView
6
from calebasse.agenda.models import Occurrence
7
from calebasse.personnes.models import Worker
8
from calebasse.ressources.models import WorkerType
9

    
10
from forms import NewAppointmentForm
11

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

    
17
class AgendaHomepageView(TemplateView):
18

    
19
    template_name = 'agenda/index.html'
20

    
21
    def get_context_data(self, **kwargs):
22
        context = super(AgendaHomepageView, self).get_context_data(**kwargs)
23
        context['workers_types'] = []
24
        context['workers_agenda'] = []
25
        context['disponnibility'] = {}
26
        context['new_appointment_form'] = NewAppointmentForm()
27
        workers = []
28
        for worker_type in WorkerType.objects.all():
29
            data = {'type': worker_type.name, 'workers': Worker.objects.for_service(self.service, worker_type) }
30
            context['workers_types'].append(data)
31
            workers.extend(data['workers'])
32

    
33
        for worker in workers:
34
            context['workers_agenda'].append({'worker': worker,
35
                    'agenda': Occurrence.objects.daily_occurrences(context['date'], [worker])})
36

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

    
40
def new_appointment(request):
41
    pass
(9-9/9)