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.
69 lines
2.6 KiB
69 lines
2.6 KiB
import os, sys
|
|
import django, json
|
|
|
|
sys.path.append("../")
|
|
os.environ['PG_PORT_5432_TCP_ADDR'] = '127.0.0.1'
|
|
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "lms.settings")
|
|
django.setup()
|
|
|
|
from courses.models import Course, NormalMap, CourseTheme, Lesson, Homework, Exam, Vertex
|
|
|
|
if __name__ == '__main__':
|
|
for course in Course.objects.all():
|
|
course_list = []
|
|
for theme in CourseTheme.objects.filter(course=course).order_by('sort'):
|
|
|
|
topic_vertex = Vertex.manager.create_with_dependencies(
|
|
course=course,
|
|
title=theme.title,
|
|
description=theme.description,
|
|
model='topic',
|
|
icon=theme.icon,
|
|
)
|
|
course_list.append(topic_vertex.id)
|
|
|
|
topic_list = []
|
|
|
|
for i in Lesson.objects.filter(theme=theme).order_by('sort'):
|
|
on_comment = i.on_comment == 'N' or i.on_comment == 'T' and i.theme.on_comment
|
|
vertex = Vertex.manager.create_with_dependencies(
|
|
course=course,
|
|
title=i.title,
|
|
description=i.description,
|
|
model='tutorial',
|
|
on_comment=on_comment,
|
|
video=i.video,
|
|
materials=i.materials.all(),
|
|
)
|
|
topic_vertex.children.add(vertex)
|
|
topic_list.append(vertex.id)
|
|
|
|
for i in Homework.objects.filter(theme=theme).order_by('sort'):
|
|
vertex = Vertex.manager.create_with_dependencies(
|
|
course=course,
|
|
title='Домашняя работа',
|
|
description=i.description,
|
|
model='task',
|
|
is_exam=False,
|
|
materials=i.materials.all(),
|
|
)
|
|
topic_vertex.children.add(vertex)
|
|
topic_list.append(vertex.id)
|
|
|
|
for i in Exam.objects.filter(theme=theme).order_by('sort'):
|
|
vertex = Vertex.manager.create_with_dependencies(
|
|
course=course,
|
|
title='Экзамен',
|
|
description=i.description,
|
|
model='task',
|
|
is_exam=True,
|
|
materials=i.materials.all(),
|
|
)
|
|
topic_vertex.children.add(vertex)
|
|
topic_list.append(vertex.id)
|
|
|
|
course_list.append(topic_list)
|
|
|
|
course_map, _is_create = NormalMap.objects.get_or_create(course=course)
|
|
course_map.dependent_elements = json.dumps(course_list)
|
|
course_map.save()
|
|
|