diff MPIWGProjects_removed.py @ 60:dc41deabc8f8

more work on projects. more cleanup.
author casties
date Thu, 02 May 2013 11:26:57 +0200
parents 1ed79b33200c
children 04fb655633ef
line wrap: on
line diff
--- a/MPIWGProjects_removed.py	Thu May 02 10:14:52 2013 +0200
+++ b/MPIWGProjects_removed.py	Thu May 02 11:26:57 2013 +0200
@@ -249,4 +249,98 @@
             return self        
 
 
+    def getContent(self, field, filter=None):
+        """Inhalt des Feldes"""
+        # logging.debug("getContent field=%s filter=%s"%(field,filter))
+        
+        if field == "short_title":
+                text = self.getContent("xdata_07")
+                if text == "":
+                        text = self.getContent("WEB_title")
+                return text
 
+        text = u''
+
+        f = getattr(self, field)
+        if isinstance(f, list):
+            # compat with old lists
+            for x in f:
+                try:
+                    text += x
+                except:
+                    text = x
+        else:
+            text = f
+
+        try:
+            if text[len(text) - 1] == ";":
+                text = text[0:len(text) - 1]
+                
+        except:
+            pass
+        
+        if text == '':  # # wozu die folgenden Zeilen??
+            text2 = text
+        else:
+            text2 = re.sub(r';([^\s])', '; \g<1>', text)
+       
+        if field == "WEB_project_description":  # #Jedenfalls darf letzteres nicht gemacht werden, falls normaler text
+            text2 = text
+            
+        # teste ob ergebnis leer und header dann nehme title
+        
+        if (text2 == '') and (field == 'WEB_project_header'):
+            return self.getContent('WEB_title')
+
+        if filter:
+            splitted = text2.split("""<p class="picture">""")
+            if len(splitted) > 1:
+                tmp = splitted[1].split("</p>")
+                # return repr(splitted[1])
+                try:
+                        self.imageURL = tmp[0].split("\"")[1].encode('utf-8')
+                except:
+                    try:
+                        self.imageURL = tmp[0].split("src=")[1].split(" ")[0].encode('utf-8')
+                    except:
+                        self.imageURL = ""
+
+                split2 = "</p>".join(tmp[1:])
+
+                text3 = splitted[0] + split2
+
+                splitted = text3.split("""<p class="picturetitle">""")
+                if len(splitted) > 1:
+                    tmp = splitted[1].split("</p>")
+                    self.imagecap = tmp[0].encode('utf-8')
+                
+                    split4 = "".join(tmp[1:])
+
+                    text5 = splitted[0] + split4
+                else:
+                    # keine caption
+                    text5 = text3
+            else:
+                # kein bild
+                text5 = text2
+        else:
+            text5 = text2
+
+        # teste ob WEB_project_description und keine fuehrenden p tags
+        if (len(text5) > 4) and (not text5[0:3] == '<p>') and (field == 'WEB_project_description'):
+            text5 = "<p>" + text5 + "</p>"
+
+
+        # filter image
+        
+        text5 = text5.lstrip().rstrip()  # loescher leerzeichen und einzelndes br
+        if (text5 == "<br>") or (text5 == "<br/>"):
+            text5 = ""
+
+        # logging.debug("getcontent: field=%s filter=%s -> %s"%(field,filter,repr(text5)))
+        return unicodify(text5)
+        # return utf8ify(text5) # return as utf-8 byte string
+
+
+
+