vigiboard / vigiboard / controllers / root.py @ dde732e5
History | View | Annotate | Download (3.67 KB)
1 |
# -*- coding: utf-8 -*-
|
---|---|
2 |
# vim:set expandtab tabstop=4 shiftwidth=4:
|
3 |
"""Main Controller"""
|
4 |
|
5 |
from tg import expose, flash, require, url, request, redirect, config |
6 |
|
7 |
from pylons.i18n import ugettext as _, lazy_ugettext as l_ |
8 |
from catwalk.tg2 import Catwalk |
9 |
from repoze.what import predicates |
10 |
|
11 |
from vigiboard.lib.base import BaseController |
12 |
from vigiboard.model import DBSession |
13 |
from vigiboard.controllers.error import ErrorController |
14 |
from vigiboard import model |
15 |
from vigiboard.controllers.secure import SecureController |
16 |
|
17 |
__all__ = ['RootController']
|
18 |
|
19 |
class RootController(BaseController): |
20 |
"""
|
21 |
The root controller for the vigiboard application.
|
22 |
|
23 |
All the other controllers and WSGI applications should be mounted on this
|
24 |
controller. For example::
|
25 |
|
26 |
panel = ControlPanelController()
|
27 |
another_app = AnotherWSGIApplication()
|
28 |
|
29 |
Keep in mind that WSGI applications shouldn't be mounted directly: They
|
30 |
must be wrapped around with :class:`tg.controllers.WSGIAppController`.
|
31 |
|
32 |
"""
|
33 |
secc = SecureController() |
34 |
|
35 |
admin = Catwalk(model, DBSession) |
36 |
|
37 |
error = ErrorController() |
38 |
|
39 |
# on charge les controleurs souhaité en dynamique
|
40 |
def __init__(self) : |
41 |
super(RootController,self).__init__() |
42 |
|
43 |
for mod in config['vigilo_mods']: |
44 |
try :
|
45 |
mymod = __import__(
|
46 |
'vigiboard.controllers.' + mod + '_ctl',globals(), locals(), [mod + 'Controller'],-1) |
47 |
setattr(self,mod,getattr(mymod,mod + 'Controller')()) |
48 |
except:
|
49 |
pass
|
50 |
|
51 |
@expose('vigiboard.templates.index') |
52 |
def index(self): |
53 |
"""Handle the front-page."""
|
54 |
return dict(page='index') |
55 |
|
56 |
@expose('vigiboard.templates.about') |
57 |
def about(self): |
58 |
"""Handle the 'about' page."""
|
59 |
return dict(page='about') |
60 |
|
61 |
@expose('vigiboard.templates.authentication') |
62 |
def auth(self): |
63 |
"""Display some information about auth* on this application."""
|
64 |
return dict(page='auth') |
65 |
|
66 |
@expose('vigiboard.templates.index') |
67 |
@require(predicates.has_permission('manage', msg=l_('Only for managers'))) |
68 |
def manage_permission_only(self, **kw): |
69 |
"""Illustrate how a page for managers only works."""
|
70 |
return dict(page='managers stuff') |
71 |
|
72 |
@expose('vigiboard.templates.index') |
73 |
@require(predicates.is_user('editor', msg=l_('Only for the editor'))) |
74 |
def editor_user_only(self, **kw): |
75 |
"""Illustrate how a page exclusive for the editor works."""
|
76 |
return dict(page='editor stuff') |
77 |
|
78 |
@expose('vigiboard.templates.login') |
79 |
def login(self, came_from=url('/')): |
80 |
"""Start the user login."""
|
81 |
login_counter = request.environ['repoze.who.logins']
|
82 |
if login_counter > 0: |
83 |
flash(_('Wrong credentials'), 'warning') |
84 |
return dict(page='login', login_counter=str(login_counter), |
85 |
came_from=came_from) |
86 |
|
87 |
@expose()
|
88 |
def post_login(self, came_from=url('/')): |
89 |
"""
|
90 |
Redirect the user to the initially requested page on successful
|
91 |
authentication or redirect her back to the login page if login failed.
|
92 |
|
93 |
"""
|
94 |
if not request.identity: |
95 |
login_counter = request.environ['repoze.who.logins'] + 1 |
96 |
redirect(url('/login', came_from=came_from, __logins=login_counter))
|
97 |
userid = request.identity['repoze.who.userid']
|
98 |
flash(_('Welcome back, %s!') % userid)
|
99 |
redirect(came_from) |
100 |
|
101 |
@expose()
|
102 |
def post_logout(self, came_from=url('/')): |
103 |
"""
|
104 |
Redirect the user to the initially requested page on logout and say
|
105 |
goodbye as well.
|
106 |
|
107 |
"""
|
108 |
flash(_('We hope to see you soon!'))
|
109 |
redirect(came_from) |