1 # vim: set et sw=4 sts=4 encoding=utf-8 :
3 from turbogears import controllers, expose
4 from turbogears import widgets as w, validators
5 from turbogears import identity, redirect
6 from cherrypy import request, response
8 # from sercom import json
10 from subcontrollers import DocenteController
13 log = logging.getLogger("sercom.controllers")
15 class Root(controllers.RootController):
17 @expose(template='.templates.welcome')
18 @identity.require(identity.has_permission('entregar'))
21 log.debug('Happy TurboGears Controller Responding For Duty')
22 return dict(now=time.ctime())
24 @expose(template='.templates.login')
25 def login(self, forward_url=None, previous_url=None, tg_errors=None, *args,
29 flash(_(u'Hubo un error en el formulario!'))
31 if not identity.current.anonymous \
32 and identity.was_login_attempted() \
33 and not identity.get_identity_errors():
34 raise redirect(forward_url)
37 previous_url = request.path
39 if identity.was_login_attempted():
40 msg = _(u'Las credenciales proporcionadas no son correctas o no '
41 'le dan acceso al recurso solicitado.')
42 elif identity.get_identity_errors():
43 msg = _(u'Debe proveer sus credenciales antes de acceder a este '
46 msg = _(u'Por favor ingrese.')
47 forward_url = request.headers.get('Referer', '/')
50 w.TextField(name='login_user', label=_(u'Usuario'),
51 validator=validators.NotEmpty()),
52 w.PasswordField(name='login_password', label=_(u'Contraseña'),
53 validator=validators.NotEmpty())
56 fields.append(w.HiddenField(name='forward_url'))
57 fields.extend([w.HiddenField(name=name) for name in request.params
58 if name not in ('login_user', 'login_password', 'login_submit',
61 submit = w.SubmitButton(name='login_submit')
63 login_form = w.TableForm(fields=fields, action=previous_url,
64 submit_text=_(u'Ingresar'), submit=submit)
66 values = dict(forward_url=forward_url)
67 values.update(request.params)
70 return dict(login_form=login_form, form_data=values, message=msg,
75 identity.current.logout()
78 docente = DocenteController()