1 # vim: set et sw=4 sts=4 encoding=utf-8 :
3 from turbogears import controllers, expose, view
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 *
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()
80 enunciado = EnunciadoController()
82 caso_de_prueba = CasoDePruebaController()
84 #{{{ Agrega summarize a namespace tg de KID
85 def summarize(text, size, concat=True, continuation='...'):
86 """Summarize a string if it's length is greater than a specified size. This
87 is useful for table listings where you don't want the table to grow because
90 >>> from sercome.controllers
91 >>> text = '''Why is it that nobody remembers the name of Johann
92 ... Gambolputty de von Ausfern-schplenden-schlitter-crasscrenbon-fried-
93 ... digger-dingle-dangle-dongle-dungle-burstein-von-knacker-thrasher-apple-
94 ... banger-horowitz-ticolensic-grander-knotty-spelltinkle-grandlich-
95 ... grumblemeyer-spelterwasser-kurstlich-himbleeisen-bahnwagen-gutenabend-
96 ... bitte-ein-nurnburger-bratwustle-gernspurten-mitz-weimache-luber-
97 ... hundsfut-gumberaber-shonedanker-kalbsfleisch-mittler-aucher von
98 ... Hautkopft of Ulm?'''
99 >>> summarize(text, 30)
100 'Why is it that nobody remem...'
101 >>> summarize(text, 68, False, ' [...]')
102 'Why is it that nobody remembers the name of Johann\nGambolputty [...]'
103 >>> summarize(text, 68, continuation=' >>')
104 'Why is it that nobody remembers the name of Johann Gambolputty de >>'
108 text = text.replace('\n', ' ')
110 text = text[:size-len(continuation)] + continuation
113 def add_custom_stdvars(vars):
114 return vars.update(dict(summarize=summarize))
116 view.variable_providers.append(add_custom_stdvars)