Project

General

Profile

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

calebasse / calebasse / views.py @ 73afaff3

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
                                     ('active-agenda',
36
                                      '/%s/agenda' % kwargs['service']),
37
                                     ('last-ressource',
38
                                      '/%s/agenda' % kwargs['service']),
39
                                     ]
40
        return super(Homepage, self).dispatch(request, **kwargs)
41

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

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