From 5cd1df8c26d5462fed3d660d965d5e2e34af8119 Mon Sep 17 00:00:00 2001 From: Leandro Lucarella Date: Wed, 31 Jan 2007 18:26:11 +0000 Subject: [PATCH] =?utf8?q?Crea=20funci=C3=B3n=20para=20kid=20"summarize".?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- sercom/controllers.py | 37 ++++++++++++++++++- sercom/kidutil.py | 7 ---- sercom/subcontrollers/docente/__init__.py | 5 --- .../subcontrollers/docente/templates/list.kid | 9 ----- 4 files changed, 36 insertions(+), 22 deletions(-) delete mode 100644 sercom/kidutil.py diff --git a/sercom/controllers.py b/sercom/controllers.py index 13f6172..5e785ea 100644 --- a/sercom/controllers.py +++ b/sercom/controllers.py @@ -1,6 +1,6 @@ # 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 @@ -77,3 +77,38 @@ class Root(controllers.RootController): docente = DocenteController() +#{{{ 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) +#}}} + diff --git a/sercom/kidutil.py b/sercom/kidutil.py deleted file mode 100644 index 82feb16..0000000 --- a/sercom/kidutil.py +++ /dev/null @@ -1,7 +0,0 @@ -# vim: set et sw=4 sts=4 encoding=utf-8 : - -def resume(text, size=15): - if text is not None and len(text) > size: - text = text[:size-3] + '...' - return text - diff --git a/sercom/subcontrollers/docente/__init__.py b/sercom/subcontrollers/docente/__init__.py index e01023d..c410e4d 100644 --- a/sercom/subcontrollers/docente/__init__.py +++ b/sercom/subcontrollers/docente/__init__.py @@ -38,11 +38,6 @@ form = TableForm(fields=[ validator=validators.Bool(if_empty=1)), ]) -def minimize(text, size=15): - if text is not None and len(text) > size: - text = text[:size] + '...' - return text - class DocenteController(controllers.Controller, identity.SecureResource): """Basic model admin interface""" require = identity.has_permission('admin') diff --git a/sercom/subcontrollers/docente/templates/list.kid b/sercom/subcontrollers/docente/templates/list.kid index f9a336d..3ae06da 100644 --- a/sercom/subcontrollers/docente/templates/list.kid +++ b/sercom/subcontrollers/docente/templates/list.kid @@ -9,15 +9,6 @@

Administración de Objetos

- - - - -- 2.43.0
Usuario