|
63
|
1 |
#! /usr/bin/env python |
|
|
2 |
|
|
|
3 |
import sys, os, os.path, time, tempfile, uuid |
|
|
4 |
|
|
|
5 |
sys.path.append(os.path.dirname(os.path.abspath(__file__))+"/../web/") |
|
|
6 |
|
|
|
7 |
from django.core.management import setup_environ |
|
|
8 |
from franceculture import settings |
|
|
9 |
|
|
|
10 |
setup_environ(settings) |
|
|
11 |
|
|
|
12 |
from franceculture.settings import * |
|
|
13 |
|
|
65
|
14 |
from ldt.ldt_utils.models import Content, Media |
|
63
|
15 |
|
|
|
16 |
|
|
|
17 |
from django.db import connection, transaction |
|
|
18 |
|
|
65
|
19 |
transaction.enter_transaction_management() |
|
63
|
20 |
|
|
65
|
21 |
try: |
|
|
22 |
cursor = connection.cursor() |
|
|
23 |
|
|
|
24 |
# Data retrieval operation - no commit required |
|
|
25 |
cursor.execute("SELECT id,external_id, videopath, src FROM ldt_utils_content", None) |
|
|
26 |
|
|
63
|
27 |
|
|
65
|
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() |