X-Git-Url: https://git.llucax.com/software/sercom.git/blobdiff_plain/2344dcf6736372c1dd359a95819fb3c2e131afc2..898fc8292d2ba43b2564d1f22bc6181d569adfe2:/sercom/controllers.py?ds=inline diff --git a/sercom/controllers.py b/sercom/controllers.py index 4d999ce..714869a 100644 --- a/sercom/controllers.py +++ b/sercom/controllers.py @@ -1,12 +1,14 @@ # vim: set et sw=4 sts=4 encoding=utf-8 : -from turbogears import controllers, expose +from turbogears import controllers, expose, view from turbogears import widgets as w, validators from turbogears import identity, redirect from cherrypy import request, response from model import * # from sercom import json +from subcontrollers import * + import logging log = logging.getLogger("sercom.controllers") @@ -60,6 +62,8 @@ class Root(controllers.RootController): login_form = w.TableForm(fields=fields, action=previous_url, submit_text=_(u'Ingresar'), submit=submit) + login_form.javascript.append( + w.JSSource("MochiKit.DOM.focusOnLoad('form_login_user');")) values = dict(forward_url=forward_url) values.update(request.params) @@ -73,3 +77,44 @@ class Root(controllers.RootController): identity.current.logout() raise redirect('/') + docente = DocenteController() + + enunciado = EnunciadoController() + + caso_de_prueba = CasoDePruebaController() + +#{{{ Agrega summarize a namespace tg de KID +def summarize(text, size, concat=True, continuation='...'): + """Summarize a string if it's length is greater than a specified size. This + is useful for table listings where you don't want the table to grow because + of a large field. + + >>> from sercome.controllers + >>> text = '''Why is it that nobody remembers the name of Johann + ... Gambolputty de von Ausfern-schplenden-schlitter-crasscrenbon-fried- + ... digger-dingle-dangle-dongle-dungle-burstein-von-knacker-thrasher-apple- + ... banger-horowitz-ticolensic-grander-knotty-spelltinkle-grandlich- + ... grumblemeyer-spelterwasser-kurstlich-himbleeisen-bahnwagen-gutenabend- + ... bitte-ein-nurnburger-bratwustle-gernspurten-mitz-weimache-luber- + ... hundsfut-gumberaber-shonedanker-kalbsfleisch-mittler-aucher von + ... Hautkopft of Ulm?''' + >>> summarize(text, 30) + 'Why is it that nobody remem...' + >>> summarize(text, 68, False, ' [...]') + 'Why is it that nobody remembers the name of Johann\nGambolputty [...]' + >>> summarize(text, 68, continuation=' >>') + 'Why is it that nobody remembers the name of Johann Gambolputty de >>' + """ + if text is not None: + if concat: + text = text.replace('\n', ' ') + if len(text) > size: + text = text[:size-len(continuation)] + continuation + return text + +def add_custom_stdvars(vars): + return vars.update(dict(summarize=summarize)) + +view.variable_providers.append(add_custom_stdvars) +#}}} +