changeset 102:bde0929d34fb

function for excerpts of project descriptions.
author casties
date Fri, 24 May 2013 08:20:47 +0200
parents a28e67fbdd31
children 79a198e7b1b7
files MPIWGProjects.py css/mpiwg.css
diffstat 2 files changed, 34 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/MPIWGProjects.py	Tue May 21 18:54:54 2013 +0200
+++ b/MPIWGProjects.py	Fri May 24 08:20:47 2013 +0200
@@ -602,13 +602,44 @@
         return None
 
 
-    def getDescription(self, filter=False):
+    def getDescription(self, filter=None, length=0):
         """returns the project description"""
         text = getattr(self, 'WEB_project_description', None)
         if isinstance(text, list):
             # compat with old lists
             text = text[0]
 
+        if filter == 'plaintext':
+            # filter out any tags, keep only text
+            try:
+                xmltext = utf8ify("<div>%s</div>"%text)
+                dom = ET.fromstring(xmltext)
+                plaintext = ""
+                for elem in dom.iter():
+                    if elem.tag == 'style':
+                        # ignore tag
+                        continue
+                    
+                    if elem.text:
+                        plaintext += elem.text
+                    if elem.tail:
+                        plaintext += elem.tail
+                        
+                    if length > 0 and len(plaintext) > length:
+                        break
+
+                text = plaintext
+            except Exception, e:
+                logging.warn("getDesciption: error parsing description! Returning everything. %s"%e)
+                
+        if length > 0 and len(text) > length:
+            # try to not break words
+            if text[length] not in [' ', '.', '?', '!']:
+                # search the last blank
+                length = text.rfind(' ', 0, length)
+
+            return text[:length] + '...'
+        
         return text
             
         
--- a/css/mpiwg.css	Tue May 21 18:54:54 2013 +0200
+++ b/css/mpiwg.css	Fri May 24 08:20:47 2013 +0200
@@ -763,6 +763,8 @@
 div.mini h2 {
     /* e.g. title for mini-books */
     font-size: 14px;
+    /* but no line if used inside box */
+    border-bottom: 0;
 }
 
 div.mini.website div.description {