LDT does not add extra html tags to project description
authorverrierj
Thu, 10 Nov 2011 11:36:15 +0100
changeset 221 fff164d7d6ad
parent 220 74738cf15d99
child 222 a413a997a5e2
LDT does not add extra html tags to project description
src/ldt/ldt/ldt_utils/models.py
--- a/src/ldt/ldt/ldt_utils/models.py	Fri Nov 04 10:23:18 2011 +0100
+++ b/src/ldt/ldt/ldt_utils/models.py	Thu Nov 10 11:36:15 2011 +0100
@@ -383,6 +383,29 @@
         else:
             return False
         
+    def save(self):
+        doc = lxml.etree.fromstring(self.ldt)
+        self.contents.clear()
+        medias = doc.xpath('/iri/medias/media')
+        
+        # Remove html tags added by flash if necessary
+        begin_str = "KERNING=\"0\">"                    
+        description = self.get_description(doc)
+        begin = description.find(begin_str) + len(begin_str)
+        end = description.find("</FONT")        
+
+        if begin > 0 and end > 0:
+            description = description[begin:end]
+            desc_node = doc.xpath('/iri/project')[0]
+            desc_node.set('abstract', description)
+            self.ldt = lxml.etree.tostring(doc, pretty_print=True)          
+        
+        for media in medias:
+            iri_id = media.get('id')
+            c = Content.objects.get(iri_id=iri_id)
+            self.contents.add(c)
+            
+        super(Project, self).save()
 
 class Segment(models.Model):