Project

General

Profile

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

calebasse / calebasse / agenda / views.py @ 5f372104

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
def redirect_today(request, service):
11
    '''If not date is given we redirect on the agenda for today'''
12
    return redirect('agenda', date=datetime.date.today().strftime('%Y-%m-%d'),
13
            service=service)
14

    
15
class AgendaHomepageView(TemplateView):
16

    
17
    template_name = 'agenda/index.html'
18

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

    
30
        for worker in workers:
31
            context['workers_agenda'].append({'worker': worker,
32
                    'agenda': Occurrence.objects.daily_occurrences(context['date'], [worker])})
33

    
34
        context['disponnibility'] = Occurrence.objects.daily_disponiblity(context['date'], workers)
35
        return context
(8-8/8)