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.
75 lines
3.1 KiB
75 lines
3.1 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 django.contrib.contenttypes.models import ContentType
|
|
from courses.models import Course, NormalMap, CourseTheme, Lesson, Homework, Exam, \
|
|
Tutorial, Task, Topic, Vertex
|
|
|
|
if __name__ == '__main__':
|
|
for course in Course.objects.all():
|
|
tree = []
|
|
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,
|
|
)
|
|
|
|
tree.append(topic_vertex.id)
|
|
children = []
|
|
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
|
|
tutor = Tutorial.objects.create(video=i.video, on_comment=on_comment)
|
|
[tutor.materials.add(j) for j in i.materials.all()]
|
|
lesson_type = ContentType.objects.get(app_label="courses", model="tutorial")
|
|
vertex = Vertex.objects.create(
|
|
course=course,
|
|
title=i.title,
|
|
description=i.description,
|
|
content_type=lesson_type,
|
|
object_id=tutor.id,
|
|
)
|
|
topic_vertex.children.add(vertex)
|
|
children.append(vertex.id)
|
|
|
|
for i in Homework.objects.filter(theme=theme).order_by('sort'):
|
|
task = Task.objects.create(is_exam=False,)
|
|
[task.materials.add(j) for j in i.materials.all()]
|
|
task_type = ContentType.objects.get(app_label="courses", model="task")
|
|
vertex = Vertex.objects.create(
|
|
course=course,
|
|
title='Домашняя работа',
|
|
description=i.description,
|
|
content_type=task_type,
|
|
object_id=task.id,
|
|
)
|
|
topic_vertex.children.add(vertex)
|
|
children.append(vertex.id)
|
|
|
|
for i in Exam.objects.filter(theme=theme).order_by('sort'):
|
|
task=Task.objects.create(is_exam=True,)
|
|
[task.materials.add(j) for j in i.materials.all()]
|
|
task_type = ContentType.objects.get(app_label="courses", model="task")
|
|
vertex = Vertex.objects.create(
|
|
course=course,
|
|
title='Экзамен',
|
|
description=i.description,
|
|
content_type=task_type,
|
|
object_id=task.id,
|
|
)
|
|
topic_vertex.children.add(vertex)
|
|
children.append(vertex.id)
|
|
|
|
tree.append(children)
|
|
|
|
course_map, _is_create = NormalMap.objects.get_or_create(course=course)
|
|
course_map.json_tree=json.dumps(tree)
|
|
course_map.save() |