src/hp/migrations/0004_kc_rel_query_content_title.py
author ymh <ymh.work@gmail.com>
Sat, 01 Dec 2012 02:20:06 +0100
changeset 104 7643c6aea04b
parent 91 eb2aa2a469e2
permissions -rw-r--r--
Added tag V00.13 for changeset 329e6650ee4e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
91
eb2aa2a469e2 add content title to relations
ymh <ymh.work@gmail.com>
parents:
diff changeset
     1
# -*- coding: utf-8 -*-
eb2aa2a469e2 add content title to relations
ymh <ymh.work@gmail.com>
parents:
diff changeset
     2
from south.v2 import DataMigration
eb2aa2a469e2 add content title to relations
ymh <ymh.work@gmail.com>
parents:
diff changeset
     3
from hp.utils import get_all_objects
eb2aa2a469e2 add content title to relations
ymh <ymh.work@gmail.com>
parents:
diff changeset
     4
from hp import settings
eb2aa2a469e2 add content title to relations
ymh <ymh.work@gmail.com>
parents:
diff changeset
     5
eb2aa2a469e2 add content title to relations
ymh <ymh.work@gmail.com>
parents:
diff changeset
     6
class Migration(DataMigration):
eb2aa2a469e2 add content title to relations
ymh <ymh.work@gmail.com>
parents:
diff changeset
     7
eb2aa2a469e2 add content title to relations
ymh <ymh.work@gmail.com>
parents:
diff changeset
     8
    def forwards(self, orm):
eb2aa2a469e2 add content title to relations
ymh <ymh.work@gmail.com>
parents:
diff changeset
     9
        url = settings.LDT_API_URL + "contents/"
eb2aa2a469e2 add content title to relations
ymh <ymh.work@gmail.com>
parents:
diff changeset
    10
        contents = get_all_objects(url, {'limit':settings.LDT_MAX_FETCH}, None)
eb2aa2a469e2 add content title to relations
ymh <ymh.work@gmail.com>
parents:
diff changeset
    11
        
eb2aa2a469e2 add content title to relations
ymh <ymh.work@gmail.com>
parents:
diff changeset
    12
        title_dict = dict([(c.get('iri_id',''), c.get('title','')) for c in contents])
eb2aa2a469e2 add content title to relations
ymh <ymh.work@gmail.com>
parents:
diff changeset
    13
        
eb2aa2a469e2 add content title to relations
ymh <ymh.work@gmail.com>
parents:
diff changeset
    14
        for rel in orm.VideoKCRel.objects.all():
eb2aa2a469e2 add content title to relations
ymh <ymh.work@gmail.com>
parents:
diff changeset
    15
            rel.content_title = title_dict.get(rel.iri_id,None)
eb2aa2a469e2 add content title to relations
ymh <ymh.work@gmail.com>
parents:
diff changeset
    16
            rel.save()
eb2aa2a469e2 add content title to relations
ymh <ymh.work@gmail.com>
parents:
diff changeset
    17
eb2aa2a469e2 add content title to relations
ymh <ymh.work@gmail.com>
parents:
diff changeset
    18
    def backwards(self, orm):
eb2aa2a469e2 add content title to relations
ymh <ymh.work@gmail.com>
parents:
diff changeset
    19
        for rel in orm.VideoKCRel.objects.all():
eb2aa2a469e2 add content title to relations
ymh <ymh.work@gmail.com>
parents:
diff changeset
    20
            rel.content_title = None
eb2aa2a469e2 add content title to relations
ymh <ymh.work@gmail.com>
parents:
diff changeset
    21
            rel.save()
eb2aa2a469e2 add content title to relations
ymh <ymh.work@gmail.com>
parents:
diff changeset
    22
eb2aa2a469e2 add content title to relations
ymh <ymh.work@gmail.com>
parents:
diff changeset
    23
    models = {
eb2aa2a469e2 add content title to relations
ymh <ymh.work@gmail.com>
parents:
diff changeset
    24
        'hp.videokcrel': {
eb2aa2a469e2 add content title to relations
ymh <ymh.work@gmail.com>
parents:
diff changeset
    25
            'Meta': {'object_name': 'VideoKCRel'},
eb2aa2a469e2 add content title to relations
ymh <ymh.work@gmail.com>
parents:
diff changeset
    26
            'content_title': ('django.db.models.fields.CharField', [], {'max_length': '1024', 'null': 'True', 'blank': 'True'}),
eb2aa2a469e2 add content title to relations
ymh <ymh.work@gmail.com>
parents:
diff changeset
    27
            'graph_id': ('django.db.models.fields.CharField', [], {'max_length': '1024'}),
eb2aa2a469e2 add content title to relations
ymh <ymh.work@gmail.com>
parents:
diff changeset
    28
            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
eb2aa2a469e2 add content title to relations
ymh <ymh.work@gmail.com>
parents:
diff changeset
    29
            'iri_id': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '255'}),
eb2aa2a469e2 add content title to relations
ymh <ymh.work@gmail.com>
parents:
diff changeset
    30
            'project_id': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'}),
eb2aa2a469e2 add content title to relations
ymh <ymh.work@gmail.com>
parents:
diff changeset
    31
            'topic_id': ('django.db.models.fields.CharField', [], {'max_length': '1024'})
eb2aa2a469e2 add content title to relations
ymh <ymh.work@gmail.com>
parents:
diff changeset
    32
        }
eb2aa2a469e2 add content title to relations
ymh <ymh.work@gmail.com>
parents:
diff changeset
    33
    }
eb2aa2a469e2 add content title to relations
ymh <ymh.work@gmail.com>
parents:
diff changeset
    34
eb2aa2a469e2 add content title to relations
ymh <ymh.work@gmail.com>
parents:
diff changeset
    35
    complete_apps = ['hp']
eb2aa2a469e2 add content title to relations
ymh <ymh.work@gmail.com>
parents:
diff changeset
    36
    symmetrical = True