Project

General

Profile

Statistics
| Branch: | Tag: | Revision:

vigiboard / vigiboard / controllers / vigiboard_controller.py @ 57f7cb3f

History | View | Annotate | Download (3.8 KB)

1
# -*- coding: utf-8 -*-
2
# vim:set expandtab tabstop=4 shiftwidth=4: 
3
from tg import expose, flash, require, url, request, redirect, config
4

    
5
from pylons.i18n import ugettext as _, lazy_ugettext as l_
6
from catwalk.tg2 import Catwalk
7
from repoze.what import predicates
8

    
9
from vigiboard.lib.base import BaseController
10
from vigiboard.model import DBSession 
11
from vigiboard.controllers.error import ErrorController
12
from vigiboard import model
13
from vigiboard.controllers.secure import SecureController
14
class Vigiboard_RootController(BaseController):
15
    """
16
    The root controller for the vigiboard application.
17
    
18
    All the other controllers and WSGI applications should be mounted on this
19
    controller. For example::
20
    
21
        panel = ControlPanelController()
22
        another_app = AnotherWSGIApplication()
23
    
24
    Keep in mind that WSGI applications shouldn't be mounted directly: They
25
    must be wrapped around with :class:`tg.controllers.WSGIAppController`.
26
    
27
    """
28
    secc = SecureController()
29
    
30
    admin = Catwalk(model, DBSession)
31
    
32
    error = ErrorController()
33

    
34
#    # on charge les controleurs souhaité en dynamique
35
#    def __init__(self) :
36
#        super(RootController,self).__init__()
37
#        a = config['app_conf']['appname']
38
#        p = __import__(a + '.config.' + a,globals(), locals(), [a + '_config'],-1)
39
#        print getattr(p,a + '_config')
40
#
41
#        for mod in config['vigilo_mods']:
42
#            try :
43
#                mymod = __import__(
44
#                    'vigiboard.controllers.' + mod + '_ctl',globals(), locals(), [mod + 'Controller'],-1)
45
#                setattr(self,mod,getattr(mymod,mod + 'Controller')())
46
#            except:
47
#                pass
48

    
49
    @expose('vigiboard.templates.index')
50
    def index(self):
51
        """Handle the front-page."""
52
        return dict(page='index')
53

    
54
    @expose('vigiboard.templates.about')
55
    def about(self):
56
        """Handle the 'about' page."""
57
        return dict(page='about')
58

    
59
    @expose('vigiboard.templates.authentication')
60
    def auth(self):
61
        """Display some information about auth* on this application."""
62
        return dict(page='auth')
63

    
64
    @expose('vigiboard.templates.index')
65
    @require(predicates.has_permission('manage', msg=l_('Only for managers')))
66
    def manage_permission_only(self, **kw):
67
        """Illustrate how a page for managers only works."""
68
        return dict(page='managers stuff')
69

    
70
    @expose('vigiboard.templates.index')
71
    @require(predicates.is_user('editor', msg=l_('Only for the editor')))
72
    def editor_user_only(self, **kw):
73
        """Illustrate how a page exclusive for the editor works."""
74
        return dict(page='editor stuff')
75

    
76
    @expose('vigiboard.templates.login')
77
    def login(self, came_from=url('/')):
78
        """Start the user login."""
79
        login_counter = request.environ['repoze.who.logins']
80
        if login_counter > 0:
81
            flash(_('Wrong credentials'), 'warning')
82
        return dict(page='login', login_counter=str(login_counter),
83
                    came_from=came_from)
84
    
85
    @expose()
86
    def post_login(self, came_from=url('/')):
87
        """
88
        Redirect the user to the initially requested page on successful
89
        authentication or redirect her back to the login page if login failed.
90
        
91
        """
92
        if not request.identity:
93
            login_counter = request.environ['repoze.who.logins'] + 1
94
            redirect(url('/login', came_from=came_from, __logins=login_counter))
95
        userid = request.identity['repoze.who.userid']
96
        flash(_('Welcome back, %s!') % userid)
97
        redirect(came_from)
98

    
99
    @expose()
100
    def post_logout(self, came_from=url('/')):
101
        """
102
        Redirect the user to the initially requested page on logout and say
103
        goodbye as well.
104
        
105
        """
106
        flash(_('We hope to see you soon!'))
107
        redirect(came_from)
108