You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
100 lines
2.6 KiB
100 lines
2.6 KiB
# coding=utf-8
|
|
import os
|
|
import django
|
|
import sys
|
|
import simplejson as json
|
|
|
|
|
|
|
|
sys.path.append("/var/www/projects/lms/")
|
|
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "lms.settings")
|
|
django.setup()
|
|
from __migrate.post_fixtures import show_progress
|
|
from storage.models import FormatIndex, Storage, CroppedImage
|
|
|
|
_fixture = json.load(open('fixtures/storage.json'))
|
|
user_pk = 1
|
|
findex = []
|
|
storage = []
|
|
crimg = []
|
|
|
|
|
|
def new_index(model, key, obj):
|
|
if str(key) in pk_map[model]:
|
|
return obj.objects.get(id=pk_map[model][str(key)])
|
|
return None
|
|
|
|
# Пример записи маршрута
|
|
pk_map = json.load(open('pk_maps.json'))
|
|
if 'storage.formatindex' not in pk_map.keys():
|
|
pk_map['storage.formatindex'] = {}
|
|
|
|
if 'storage.storage' not in pk_map.keys():
|
|
pk_map['storage.storage'] = {}
|
|
|
|
if 'storage.croppedimage' not in pk_map.keys():
|
|
pk_map['storage.croppedimage'] = {}
|
|
|
|
|
|
for i in _fixture:
|
|
if i['model'] == 'storage.formatindex':
|
|
findex.append(i)
|
|
elif i['model'] == 'storage.storage':
|
|
storage.append(i)
|
|
elif i['model'] == 'storage.croppedimage':
|
|
crimg.append(i)
|
|
|
|
print u'\nFormatIndex'
|
|
_now = 0
|
|
big_len = len(findex)
|
|
show_progress(big_len, _now)
|
|
|
|
for i in findex:
|
|
f = FormatIndex.objects.create(
|
|
f_type=i['fields']['f_type'],
|
|
name=i['fields']['name'],
|
|
description=i['fields']['description'],
|
|
icon=i['fields']['icon'],
|
|
icon_class=i['fields']['icon_class'],
|
|
)
|
|
pk_map['storage.formatindex'][str(i['pk'])] = str(f.id)
|
|
_now += 1
|
|
show_progress(big_len, _now)
|
|
|
|
print u'\nStorage'
|
|
_now = 0
|
|
big_len = len(storage)
|
|
show_progress(big_len, _now)
|
|
|
|
for i in storage:
|
|
s = Storage.objects.create(
|
|
loaded=i['fields']['loaded'],
|
|
name=i['fields']['name'],
|
|
key=i['fields']['key'],
|
|
original=i['fields']['original'],
|
|
f_format=new_index('storage.formatindex', i['fields']['f_format'], FormatIndex),
|
|
description=i['fields']['description'],
|
|
date=i['fields']['date'],
|
|
error=i['fields']['error'],
|
|
)
|
|
pk_map['storage.storage'][str(i['pk'])] = str(s.id)
|
|
_now += 1
|
|
show_progress(big_len, _now)
|
|
|
|
print u'\nCroppedImg'
|
|
_now = 0
|
|
big_len = len(crimg)
|
|
show_progress(big_len, _now)
|
|
|
|
for i in crimg:
|
|
c = CroppedImage.objects.create(
|
|
original=new_index('storage.storage', i['fields']['original'], Storage),
|
|
big=i['fields']['big'],
|
|
middle=i['fields']['middle'],
|
|
small=i['fields']['small'],
|
|
cropped=i['fields']['cropped'],
|
|
)
|
|
pk_map['storage.croppedimage'][str(i['pk'])] = str(c.id)
|
|
_now += 1
|
|
show_progress(big_len, _now)
|
|
json.dump(pk_map, open('pk_maps.json', 'w'))
|
|
|