changeset 207:938add25f81b

export shortenString to web
author casties
date Mon, 01 Jul 2013 12:59:10 +0200
parents 31b28f369fd3
children 6d6076e28430
files MPIWGHelper.py MPIWGRoot.py SrvTxtUtils.py
diffstat 3 files changed, 11 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- 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
 
 
 #
--- 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"""
--- 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:])