# HG changeset patch # User casties # Date 1372676350 -7200 # Node ID 938add25f81b435684bd191ce6aa51b0d3f4324d # Parent 31b28f369fd348e5ac96fd9dbe3b953c5eb02d41 export shortenString to web diff -r 31b28f369fd3 -r 938add25f81b MPIWGHelper.py --- a/MPIWGHelper.py Thu Jun 27 17:46:28 2013 +0200 +++ b/MPIWGHelper.py Mon Jul 01 12:59:10 2013 +0200 @@ -91,10 +91,8 @@ # encode unicode object or string into byte string in utf-8 representation. utf8ify = SrvTxtUtils.utf8ify -def shortenString(s, l, ellipsis='...'): - """returns a string of length l (or l-1) by omitting characters in the middle of s, replacing with ellipsis.""" - l1 = int((l - len(ellipsis)) / 2) - return "%s%s%s"%(s[:l1],ellipsis,s[-l1:]) +# returns a string of length l (or l-1) by omitting characters in the middle of s, replacing with ellipsis. +shortenString = SrvTxtUtils.shortenString # diff -r 31b28f369fd3 -r 938add25f81b MPIWGRoot.py --- a/MPIWGRoot.py Thu Jun 27 17:46:28 2013 +0200 +++ b/MPIWGRoot.py Mon Jul 01 12:59:10 2013 +0200 @@ -5,14 +5,12 @@ import os import logging from OFS.Folder import Folder -import sys from Products.ZSQLExtend.ZSQLExtend import ZSQLExtendFolder import MPIWGHelper import updatePersonalWWW -import MPIWGStaff -from SrvTxtUtils import getInt, unicodify, refreshingImageFileIndexHtml, getDateString +from SrvTxtUtils import getInt, unicodify, refreshingImageFileIndexHtml, getDateString, shortenString class MPIWGRoot(ZSQLExtendFolder): @@ -123,6 +121,11 @@ """Return a formatted date string.""" return getDateString(**args) + + def shortenString(self, s, l, ellipsis='... '): + """returns a string of length l (or l-1) by omitting characters in the middle of s, replacing with ellipsis.""" + return shortenString(s, l, ellipsis=ellipsis) + def getSubsections(self, here=None): """return sub-navigation elements i.e. elements below sections""" diff -r 31b28f369fd3 -r 938add25f81b SrvTxtUtils.py --- a/SrvTxtUtils.py Thu Jun 27 17:46:28 2013 +0200 +++ b/SrvTxtUtils.py Mon Jul 01 12:59:10 2013 +0200 @@ -213,6 +213,9 @@ def shortenString(s, l, ellipsis='...'): """returns a string of length l (or l-1) by omitting characters in the middle of s, replacing with ellipsis.""" + if len(s) <= l: + return s + l1 = int((l - len(ellipsis)) / 2) return "%s%s%s"%(s[:l1],ellipsis,s[-l1:])