Project

General

Profile

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

calebasse / calebasse / views.py @ 05a6bb20

1
# -*- coding: utf-8 -*-
2

    
3
from django.shortcuts import render, redirect
4
from django.template.defaultfilters import slugify
5

    
6
from cbv import HOME_SERVICE_COOKIE, TemplateView
7

    
8
from calebasse.ressources.models import Service
9
from calebasse.middleware.request import get_request
10
from calebasse.utils import is_validator
11

    
12

    
13
APPLICATIONS = (
14
        (u'Gestion des dossiers', 'dossiers', False),
15
        (u'Agenda', 'agenda', False),
16
        (u'Saisie des actes', 'actes', True),
17
        (u'Facturation et décompte', 'facturation', True),
18
        (u'Gestion des personnes', 'personnes', True),
19
        (u'Gestion des ressources', 'ressources', True),
20
        (u'Statistiques', 'statistics', True),
21
)
22

    
23
def redirect_to_homepage(request):
24
    service_name = request.COOKIES.get(HOME_SERVICE_COOKIE, 'cmpp').lower()
25
    return redirect('homepage', service=service_name)
26

    
27
class Homepage(TemplateView):
28
    template_name='calebasse/homepage.html'
29
    cookies_to_clear = [('agenda-tabs', )]
30

    
31
    def dispatch(self, request, **kwargs):
32
        if 'service' in kwargs:
33
            self.cookies_to_clear = [('agenda-tabs',
34
                                      '/%s/agenda' % kwargs['service']),
35
                                     ('agenda-ressource-tabs',
36
                                      '/%s/agenda' % kwargs['service']),
37
                                     ]
38
        return super(Homepage, self).dispatch(request, **kwargs)
39

    
40
    def get_context_data(self, **kwargs):
41
        services = Service.objects.values_list('name', 'slug')
42
        services = sorted(services, key=lambda tup: tup[0])
43
        ctx = super(Homepage, self).get_context_data(**kwargs)
44
        applications = list(APPLICATIONS)
45
        ctx.update({
46
            'applications': applications,
47
            'services': services,
48
            'service_name': self.service.name,
49
        })
50
        return ctx
51

    
52
homepage = Homepage.as_view()
(16-16/17)