Project

General

Profile

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

calebasse / calebasse / agenda / views.py @ f8ad3b42

1
import ipdb
2
import datetime
3

    
4
from django.shortcuts import redirect
5

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

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

    
16
class AgendaHomepageView(TemplateView):
17

    
18
    template_name = 'agenda/index.html'
19

    
20
    def get_context_data(self, **kwargs):
21
        context = super(AgendaHomepageView, self).get_context_data(**kwargs)
22
        context['workers_types'] = []
23
        context['workers'] = []
24
        context['disponnibility'] = {}
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
            context['workers'].extend(Worker.objects.for_service(self.service, worker_type))
29

    
30
        context['disponnibility'] = Occurrence.objects.daily_disponiblity(context['date'], context['workers'])
31
        return context
(7-7/7)