web/ldt/ldt_utils/models.py
changeset 16 b3692a42ac79
parent 10 84e31387a741
child 41 73753ea1dcef
child 54 24397932219d
--- a/web/ldt/ldt_utils/models.py	Thu Jun 10 12:17:51 2010 +0200
+++ b/web/ldt/ldt_utils/models.py	Thu Jun 10 18:56:59 2010 +0200
@@ -2,7 +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_iri
+from utils import create_ldt, copy_ldt, create_empty_iri
 import os
 import os.path
 import uuid
@@ -50,13 +50,18 @@
         
     def save(self):
         # create iri file if needed
-        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)
-            file = open(iri_file_path,"w")
-            create_iri(file, self, "IRI")
+        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)
+                file = open(iri_file_path,"w")
+                create_empty_iri(file, self, "IRI")
+        except Exception, e:
+            if os.path.exists(iri_file_path):
+                os.remove(iri_file_path)
+                raise e
         # update it 
         super(Content, self).save()