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.
116 lines
3.1 KiB
116 lines
3.1 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 access.models import User, Subscription, ActionJ
|
|
|
|
_fixture = json.load(open('fixtures/access.json'))
|
|
user_pk = 1
|
|
users = []
|
|
subs = []
|
|
acts = []
|
|
actjs = []
|
|
|
|
|
|
# Пример записи маршрута
|
|
pk_map = json.load(open('pk_maps.json'))
|
|
if 'access.user' not in pk_map:
|
|
pk_map['access.user'] = {}
|
|
|
|
if 'access.subscription' not in pk_map:
|
|
pk_map['access.subscription'] = {}
|
|
|
|
if 'access.actionj' not in pk_map:
|
|
pk_map['access.actionj'] = {}
|
|
|
|
for i in _fixture:
|
|
if i['model'] == 'access.user':
|
|
users.append(i)
|
|
elif i['model'] == 'access.subscription':
|
|
subs.append(i)
|
|
elif i['model'] == 'access.actionj':
|
|
actjs.append(i)
|
|
|
|
print u'\nUsers'
|
|
_now = 0
|
|
big_len = len(users)
|
|
show_progress(big_len, _now)
|
|
|
|
for i in users:
|
|
u = User.objects.create(
|
|
password=i['fields']['password'],
|
|
email=i['fields']['email'],
|
|
changed_email=i['fields']['changed_email'],
|
|
phone=i['fields']['phone'],
|
|
back_phone=i['fields']['back_phone'],
|
|
status=i['fields']['status'],
|
|
in_role=i['fields']['in_role'],
|
|
deactivate=i['fields']['deactivate'],
|
|
city=i['fields']['city'],
|
|
b_day=i['fields']['b_day'],
|
|
token=i['fields']['token'],
|
|
activate_time=i['fields']['activate_time'],
|
|
reg_status=i['fields']['reg_status'],
|
|
is_active=i['fields']['is_active'],
|
|
is_admin=i['fields']['is_admin'],
|
|
is_staff=i['fields']['is_staff'],
|
|
avatar=i['fields']['avatar'],
|
|
fname=i['fields']['fname'],
|
|
name=i['fields']['name'],
|
|
oname=i['fields']['oname'],
|
|
skype='',
|
|
facebook='',
|
|
vk='',
|
|
linkedin='',
|
|
odnoklassniki='',
|
|
date_joined=i['fields']['date_joined']
|
|
)
|
|
_now += 1
|
|
show_progress(big_len, _now)
|
|
pk_map['access.user'][str(i['pk'])] = str(u.id)
|
|
|
|
print u'\nSubscriptions'
|
|
_now = 0
|
|
big_len = len(subs)
|
|
show_progress(big_len, _now)
|
|
|
|
for i in subs:
|
|
s = Subscription.objects.create(
|
|
owner=User.objects.get(id=pk_map['access.user'][str(i['fields']['owner'])]),
|
|
news=i['fields']['news'],
|
|
teacher=i['fields']['teacher'],
|
|
new_comments=i['fields']['new_comments'],
|
|
send_sms=i['fields']['send_sms'],
|
|
courses=i['fields']['courses'],
|
|
)
|
|
_now += 1
|
|
show_progress(big_len, _now)
|
|
pk_map['access.subscription'][str(i['pk'])] = str(s.id)
|
|
|
|
print u'\nActions'
|
|
_now = 0
|
|
big_len = len(actjs)
|
|
show_progress(big_len, _now)
|
|
|
|
for i in actjs:
|
|
a = ActionJ.objects.create(
|
|
student=User.objects.get(id=pk_map['access.user'][str(i['fields']['student'])]),
|
|
a_type=i['fields']['a_type'],
|
|
place=i['fields']['place'],
|
|
date=i['fields']['date'],
|
|
text=i['fields']['text'],
|
|
)
|
|
_now += 1
|
|
show_progress(big_len, _now)
|
|
pk_map['access.actionj'][str(i['pk'])] = str(a.id)
|
|
|
|
|
|
json.dump(pk_map, open('pk_maps.json', 'w'))
|
|
|