sql/update_db_0_13_to_0_16.2.py
changeset 65 c838c80d5ba7
parent 63 7b721b427b73
equal deleted inserted replaced
64:0f3718a5c797 65:c838c80d5ba7
     9 
     9 
    10 setup_environ(settings)
    10 setup_environ(settings)
    11 
    11 
    12 from franceculture.settings import *
    12 from franceculture.settings import *
    13 
    13 
    14 from ldt.ldt_utils.model import Content, Media
    14 from ldt.ldt_utils.models import Content, Media
    15 
    15 
    16 
    16 
    17 from django.db import connection, transaction
    17 from django.db import connection, transaction
    18 cursor = connection.cursor()
       
    19 
    18 
    20 # Data retrieval operation - no commit required
    19 transaction.enter_transaction_management()
    21 cursor.execute("SELECT id,external_id, videopath, src FROM ldt_utils_content", None)
       
    22 
    20 
    23 
    21 try:
    24 for row in cursor.fetchall():
    22     cursor = connection.cursor()
    25     new_media = Media(external_id = row[1], videopath=row[2], src=row[3])
       
    26     new_media.save()
       
    27     
    23     
    28     content = Content.objects.get(id=row[0])
    24     # Data retrieval operation - no commit required
    29     content.media_obj = new_media
    25     cursor.execute("SELECT id,external_id, videopath, src FROM ldt_utils_content", None)
    30     
    26     
    31     content.save()
    27     
    32 
    28     for row in cursor.fetchall():
       
    29         new_media = Media(external_id = row[1], videopath=row[2], src=row[3])
       
    30         new_media.save()
       
    31         
       
    32         content = Content.objects.get(id=row[0])
       
    33         content.media_obj = new_media
       
    34         
       
    35         content.save()
       
    36 except Exception as inst:
       
    37     transaction.rollback()
       
    38 else:
       
    39     transaction.commit()
       
    40 finally:
       
    41     transaction.leave_transaction_management()