web/ldt/ldt_utils/models.py
changeset 54 24397932219d
parent 16 b3692a42ac79
child 57 3a3c15c462f8
--- a/web/ldt/ldt_utils/models.py	Thu Jun 17 11:24:33 2010 +0200
+++ b/web/ldt/ldt_utils/models.py	Thu Jun 17 15:04:36 2010 +0200
@@ -2,8 +2,7 @@
 from django.conf import settings
 from ldt.core.models import Document, Owner
 from django.utils.translation import ugettext_lazy as _
-from utils import create_ldt, copy_ldt, create_empty_iri
-import os
+from utils import create_ldt, copy_ldt, create_empty_iri, update_iri
 import os.path
 import uuid
 import xml
@@ -48,20 +47,28 @@
         writer.deleteDocuments(lucene.Term("iri_id", self.iri_id))
         writer.commit()
         
+    #TODO: better manage the change in .iri name and error scenario (save in temp file + rename
     def save(self):
         # create iri file if needed
+        created = False
         try:
             iri_file_path = self.iri_file_path()
             if not os.path.exists(iri_file_path):
                 dir = os.path.dirname(iri_file_path)
                 if not os.path.exists(dir):
                     os.makedirs(dir)
+                created = True
                 file = open(iri_file_path,"w")
                 create_empty_iri(file, self, "IRI")
+            else:
+                created = False
+                update_iri(iri_file_path, self, "IRI")
+                
         except Exception, e:
-            if os.path.exists(iri_file_path):
-                os.remove(iri_file_path)
-                raise e
+            if created:
+                if os.path.exists(iri_file_path):
+                    os.remove(iri_file_path)
+            raise e
         # update it 
         super(Content, self).save()