migrate more data

This commit is contained in:
j 2011-12-04 18:05:48 +01:00
commit f435f2b14b
2 changed files with 103 additions and 7 deletions

View file

@ -29,9 +29,11 @@ from datetime import datetime
from ox.utils import json
import ox
from item.models import Item
from annotation.models import Annotation, Layer
from annotation.models import Annotation
from archive.models import File
from urlalias.models import IDAlias, LayerAlias
from urlalias.models import IDAlias, LayerAlias, ListAlias
from place.models import Place
from itemlist.models import List
from django.db import connection, transaction
@ -41,6 +43,10 @@ with open('users.json') as f: users = json.load(f)
with open('padma_files.json') as f: padma = json.load(f)
with open('padma_locations.json') as f: locations = json.load(f)
with open('padma_lists.json') as f: lists = json.load(f)
with open('padma_data.json') as f: padma_data = json.load(f)
longest_username = max([len(u['username'].strip()) for u in users]) + 1
@ -65,7 +71,7 @@ for u in users:
profile.set_level('member')
profile.save()
for g in u['groups']:
if g and g.strip() and g not 'admin':
if g and g.strip() and g != 'admin':
group, created = Group.objects.get_or_create(name=g)
user.groups.add(group)
@ -153,3 +159,36 @@ for oldId in sorted(padma, key=lambda x: padma[x]['created']):
f.save()
i += 1
print item, item.available
#lists
for l in lists:
l['user'] = User.objects.get(username=l['user'])
p = List(name=l['name'], user=l['user'])
p.type = l['type'] == 'static' and 'static' or 'smart'
p.status = l['public'] and 'featured' or 'private'
p.description = l['description']
p.save()
if l['type'] == 'static':
for v in l['videos']:
i = Item.objects.get(data__contains=v)
p.add(i)
else:
key = l['query']['key']
value= l['query']['value']
if key == '': key = '*'
p.query = {'conditions': [{'key': key, 'value': value, 'operator': '='}], 'operator': '&'}
p.save()
alias, created = ListAlias.objects.get_or_create(old=l['id'])
alias.new = p.get_id()
alias.save()
#Places
for l in locations:
oldId = l.pop('id')
l['user'] = User.objects.get(username=l['user'])
l['created'] = datetime.fromtimestamp(int(l['created']))
l['modified'] = datetime.fromtimestamp(int(l['modified']))
p = Place(**l)
p.save()
#FIXME matches