sql/update_db_0_13_to_0_16.2.py
changeset 65 c838c80d5ba7
parent 63 7b721b427b73
--- a/sql/update_db_0_13_to_0_16.2.py	Tue Sep 21 06:35:54 2010 +0200
+++ b/sql/update_db_0_13_to_0_16.2.py	Tue Sep 21 09:38:30 2010 +0200
@@ -11,22 +11,31 @@
 
 from franceculture.settings import *
 
-from ldt.ldt_utils.model import Content, Media
+from ldt.ldt_utils.models import Content, Media
 
 
 from django.db import connection, transaction
-cursor = connection.cursor()
 
-# Data retrieval operation - no commit required
-cursor.execute("SELECT id,external_id, videopath, src FROM ldt_utils_content", None)
-
+transaction.enter_transaction_management()
 
-for row in cursor.fetchall():
-    new_media = Media(external_id = row[1], videopath=row[2], src=row[3])
-    new_media.save()
+try:
+    cursor = connection.cursor()
+    
+    # Data retrieval operation - no commit required
+    cursor.execute("SELECT id,external_id, videopath, src FROM ldt_utils_content", None)
+    
     
-    content = Content.objects.get(id=row[0])
-    content.media_obj = new_media
-    
-    content.save()
-
+    for row in cursor.fetchall():
+        new_media = Media(external_id = row[1], videopath=row[2], src=row[3])
+        new_media.save()
+        
+        content = Content.objects.get(id=row[0])
+        content.media_obj = new_media
+        
+        content.save()
+except Exception as inst:
+    transaction.rollback()
+else:
+    transaction.commit()
+finally:
+    transaction.leave_transaction_management()
\ No newline at end of file