48 writer.commit() |
48 writer.commit() |
49 |
49 |
50 #TODO: better manage the change in .iri name and error scenario (save in temp file + rename |
50 #TODO: better manage the change in .iri name and error scenario (save in temp file + rename |
51 def save(self): |
51 def save(self): |
52 # create iri file if needed |
52 # create iri file if needed |
|
53 created = False |
53 try: |
54 try: |
54 iri_file_path = self.iri_file_path() |
55 iri_file_path = self.iri_file_path() |
55 if not os.path.exists(iri_file_path): |
56 if not os.path.exists(iri_file_path): |
56 dir = os.path.dirname(iri_file_path) |
57 dir = os.path.dirname(iri_file_path) |
57 if not os.path.exists(dir): |
58 if not os.path.exists(dir): |
58 os.makedirs(dir) |
59 os.makedirs(dir) |
|
60 created = True |
59 file = open(iri_file_path,"w") |
61 file = open(iri_file_path,"w") |
60 create_empty_iri(file, self, "IRI") |
62 create_empty_iri(file, self, "IRI") |
61 else: |
63 else: |
|
64 created = False |
62 update_iri(iri_file_path, self, "IRI") |
65 update_iri(iri_file_path, self, "IRI") |
63 |
66 |
64 except Exception, e: |
67 except Exception, e: |
65 if os.path.exists(iri_file_path): |
68 if created: |
66 os.remove(iri_file_path) |
69 if os.path.exists(iri_file_path): |
67 raise e |
70 os.remove(iri_file_path) |
|
71 raise e |
68 # update it |
72 # update it |
69 super(Content, self).save() |
73 super(Content, self).save() |
70 |
74 |
71 def __unicode__(self): |
75 def __unicode__(self): |
72 return str(self.id) + ": " + self.iri_id |
76 return str(self.id) + ": " + self.iri_id |