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.
277 lines
7.9 KiB
277 lines
7.9 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 courses.models import Course, CourseTheme, Lesson, Homework, Exam, Skills, SkillJ, Achievements, CourseBuilder
|
|
from management.models import Comment
|
|
from storage.models import Storage
|
|
|
|
_fixture = json.load(open('fixtures/courses.json'))
|
|
user_pk = 1
|
|
courses = []
|
|
lessons = []
|
|
themes = []
|
|
homeworks = []
|
|
exams = []
|
|
skills = []
|
|
skillsj = []
|
|
achs = []
|
|
|
|
|
|
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 'courses.course' not in pk_map.keys():
|
|
pk_map['courses.course'] = {}
|
|
|
|
if 'courses.coursetheme' not in pk_map.keys():
|
|
pk_map['courses.coursetheme'] = {}
|
|
|
|
if 'courses.lesson' not in pk_map.keys():
|
|
pk_map['courses.lesson'] = {}
|
|
|
|
if 'courses.homework' not in pk_map.keys():
|
|
pk_map['courses.homework'] = {}
|
|
|
|
if 'courses.exam' not in pk_map.keys():
|
|
pk_map['courses.exam'] = {}
|
|
|
|
if 'courses.skills' not in pk_map.keys():
|
|
pk_map['courses.skills'] = {}
|
|
|
|
if 'courses.skillj' not in pk_map.keys():
|
|
pk_map['courses.skillj'] = {}
|
|
|
|
if 'courses.achievements' not in pk_map.keys():
|
|
pk_map['courses.achievements'] = {}
|
|
|
|
for i in _fixture:
|
|
if i['model'] == 'courses.course':
|
|
if i not in courses:
|
|
courses.append(i)
|
|
|
|
elif i['model'] == 'courses.coursetheme':
|
|
if i not in themes:
|
|
themes.append(i)
|
|
|
|
elif i['model'] == 'courses.lesson':
|
|
if i not in lessons:
|
|
lessons.append(i)
|
|
|
|
elif i['model'] == 'courses.homework':
|
|
if i not in homeworks:
|
|
homeworks.append(i)
|
|
|
|
elif i['model'] == 'courses.exam':
|
|
if i not in exams:
|
|
exams.append(i)
|
|
|
|
elif i['model'] == 'courses.skills':
|
|
if i not in skillsj:
|
|
skills.append(i)
|
|
|
|
elif i['model'] == 'courses.skillj':
|
|
if i not in skillsj:
|
|
skillsj.append(i)
|
|
|
|
elif i['model'] == 'courses.achievements':
|
|
if i not in achs:
|
|
achs.append(i)
|
|
|
|
print '\nCourse'
|
|
_now = 0
|
|
big_len = len(courses)
|
|
show_progress(big_len, _now)
|
|
|
|
for i in courses:
|
|
c = Course.objects.create(
|
|
level=i['fields']['level'],
|
|
public=True,
|
|
title=i['fields']['title'],
|
|
description=i['fields']['description'],
|
|
image=i['fields']['image'],
|
|
big_image=i['fields']['big_image'],
|
|
page=i['fields']['page'],
|
|
preview=i['fields']['preview'],
|
|
sort=i['fields']['sort'],
|
|
use_fail=i['fields']['use_fail'],
|
|
basic_len=i['fields']['basic_len'],
|
|
addition_len=i['fields']['addition_len'],
|
|
min_price=i['fields']['min_price'],
|
|
buy_icon=i['fields']['buy_icon']
|
|
)
|
|
|
|
pk_map['courses.course'][str(i['pk'])] = str(c.id)
|
|
_now += 1
|
|
show_progress(big_len, _now)
|
|
|
|
print u'\nCourseTheme'
|
|
_now = 0
|
|
big_len = len(themes)
|
|
show_progress(big_len, _now)
|
|
|
|
for i in themes:
|
|
c = CourseTheme.objects.create(
|
|
price_type='E' if i['fields']['type'] == 'A' else i['fields']['type'],
|
|
_type='E' if i['fields']['type'] == 'A' else i['fields']['type'],
|
|
icon=i['fields']['icon'],
|
|
course=new_index('courses.course', i['fields']['course'], Course),
|
|
sort=i['fields']['sort'],
|
|
title=i['fields']['title'],
|
|
description=i['fields']['description'],
|
|
)
|
|
# print i['fields']['course']
|
|
# print new_index('courses.course', i['fields']['course'], Course)
|
|
pk_map['courses.coursetheme'][str(i['pk'])] = str(c.id)
|
|
_now += 1
|
|
show_progress(big_len, _now)
|
|
|
|
print u'\nLessons'
|
|
_now = 0
|
|
big_len = len(lessons)
|
|
show_progress(big_len, _now)
|
|
for i in lessons:
|
|
c = Lesson.objects.create(
|
|
free=i['fields']['free'],
|
|
token=i['fields']['token'],
|
|
title=i['fields']['title'],
|
|
sort=i['fields']['sort'],
|
|
course=new_index('courses.course', i['fields']['course'], Course),
|
|
theme=new_index('courses.coursetheme', i['fields']['theme'], CourseTheme),
|
|
description=i['fields']['description'],
|
|
video=i['fields']['video']
|
|
)
|
|
for key in i['fields']['materials']:
|
|
c.materials.add(new_index('storage.storage', key, Storage))
|
|
|
|
for key in i['fields']['comments']:
|
|
# print key
|
|
# print new_index('management.comment', key, Comment)
|
|
c.comments.add(new_index('management.comment', key, Comment))
|
|
|
|
pk_map['courses.lesson'][str(i['pk'])] = str(c.id)
|
|
_now += 1
|
|
show_progress(big_len, _now)
|
|
|
|
print u'\nHomework'
|
|
_now = 0
|
|
big_len = len(homeworks)
|
|
show_progress(big_len, _now)
|
|
|
|
for i in homeworks:
|
|
c = Homework.objects.create(
|
|
token=i['fields']['token'],
|
|
course=new_index('courses.course', i['fields']['course'], Course),
|
|
theme=new_index('courses.coursetheme', i['fields']['theme'], CourseTheme),
|
|
description=i['fields']['description'],
|
|
sort=1
|
|
)
|
|
for key in i['fields']['materials']:
|
|
c.materials.add(new_index('storage.storage', key, Storage))
|
|
_now += 1
|
|
show_progress(big_len, _now)
|
|
pk_map['courses.homework'][str(i['pk'])] = str(c.id)
|
|
|
|
print u'\nExams'
|
|
_now = 0
|
|
big_len = len(exams)
|
|
show_progress(big_len, _now)
|
|
|
|
for i in exams:
|
|
tm = CourseTheme.objects.create(
|
|
course=new_index('courses.course', i['fields']['course'], Course),
|
|
_type='Ex'
|
|
)
|
|
pk_map['courses.coursetheme'][str(tm.id)] = str(tm.id)
|
|
c = Exam.objects.create(
|
|
token=i['fields']['token'],
|
|
sort=1,
|
|
course=new_index('courses.course', i['fields']['course'], Course),
|
|
theme=tm,
|
|
icon=new_index('storage.storage', i['fields']['diploma'], Storage),
|
|
title=i['fields']['title'],
|
|
description=i['fields']['description'],
|
|
diploma=new_index('storage.storage', i['fields']['diploma'], Storage)
|
|
)
|
|
for key in i['fields']['materials']:
|
|
c.materials.add(new_index('storage.storage', key, Storage))
|
|
_now += 1
|
|
show_progress(big_len, _now)
|
|
pk_map['courses.exam'][str(i['pk'])] = str(c.id)
|
|
|
|
print u'\nПереформировать порядок'
|
|
for course in Course.objects.all():
|
|
_count = 1
|
|
#print course
|
|
for _type in ['B', 'M', 'Ex', 'E', 'P']:
|
|
for theme in CourseTheme.objects.filter(course=course, _type=_type):
|
|
theme.sort = _count
|
|
_count += 1
|
|
theme.save()
|
|
#print _count
|
|
|
|
print u'\nКарты курсов'
|
|
for course in Course.objects.all():
|
|
CourseBuilder(course).main()
|
|
|
|
print u'\nSkills'
|
|
_now = 0
|
|
big_len = len(skills)
|
|
show_progress(big_len, _now)
|
|
|
|
for i in skills:
|
|
c, c2 = Skills.objects.get_or_create(
|
|
title=i['fields']['title'],
|
|
color=i['fields']['color']
|
|
)
|
|
_now += 1
|
|
show_progress(big_len, _now)
|
|
pk_map['courses.skills'][str(i['pk'])] = str(c.id)
|
|
|
|
print u'\nSkillsJ'
|
|
_now = 0
|
|
big_len = len(skillsj)
|
|
show_progress(big_len, _now)
|
|
|
|
for i in skillsj:
|
|
c, c2 = SkillJ.objects.get_or_create(
|
|
skill=new_index('courses.skills', i['fields']['skill'], Skills),
|
|
lesson=new_index('courses.lesson', i['fields']['lesson'], Lesson),
|
|
size=i['fields']['size']
|
|
)
|
|
_now += 1
|
|
show_progress(big_len, _now)
|
|
pk_map['courses.skillj'][str(i['pk'])] = str(c.id)
|
|
|
|
print u'\nAchivements'
|
|
_now = 0
|
|
big_len = len(achs)
|
|
show_progress(big_len, _now)
|
|
|
|
for i in achs:
|
|
c, c2 = Achievements.objects.get_or_create(
|
|
tech_name=i['fields']['tech_name'],
|
|
icon=i['fields']['icon'],
|
|
title=i['fields']['title'],
|
|
image=i['fields']['image'],
|
|
background=i['fields']['background'],
|
|
border=i['fields']['border'],
|
|
)
|
|
_now += 1
|
|
show_progress(big_len, _now)
|
|
pk_map['courses.achievements'][str(i['pk'])] = str(c.id)
|
|
|
|
for course in Course.objects.all():
|
|
course.build_map()
|
|
json.dump(pk_map, open('pk_maps.json', 'w'))
|
|
|