|
|
|
@ -1,5 +1,7 @@ |
|
|
|
import csv |
|
|
|
import csv |
|
|
|
import os |
|
|
|
import os |
|
|
|
|
|
|
|
import random |
|
|
|
|
|
|
|
import string |
|
|
|
import sys |
|
|
|
import sys |
|
|
|
|
|
|
|
|
|
|
|
import django |
|
|
|
import django |
|
|
|
@ -30,10 +32,19 @@ if __name__ == '__main__': |
|
|
|
row.pop('mentors', None).split("[")[1].split("]")[0].split(", ") |
|
|
|
row.pop('mentors', None).split("[")[1].split("]")[0].split(", ") |
|
|
|
course, _is_create = Course.objects.get_or_create(**row) |
|
|
|
course, _is_create = Course.objects.get_or_create(**row) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
map_obj = CourseMap.objects.create(course=course) |
|
|
|
|
|
|
|
route_obj = CourseRoute.objects.create( |
|
|
|
|
|
|
|
name='''%s''' % course.title, |
|
|
|
|
|
|
|
out_key=''.join(random.choice(string.ascii_letters) for x in range(15)), |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
PivotCourseMap.objects.create(map_course=map_obj, route=route_obj, sort=0) |
|
|
|
|
|
|
|
course.route = route_obj |
|
|
|
|
|
|
|
course.save() |
|
|
|
|
|
|
|
|
|
|
|
try: |
|
|
|
try: |
|
|
|
for teacher in teachers: |
|
|
|
for teacher in teachers: |
|
|
|
if teacher: |
|
|
|
if teacher: |
|
|
|
teacher = get_user_model().objects.get(id=teacher).token |
|
|
|
teacher = get_user_model().objects.get(id=teacher).out_key |
|
|
|
InApiTeacher.add_teacher(course.slug, teacher) |
|
|
|
InApiTeacher.add_teacher(course.slug, teacher) |
|
|
|
|
|
|
|
|
|
|
|
except get_user_model().DoesNotExist: |
|
|
|
except get_user_model().DoesNotExist: |
|
|
|
@ -47,7 +58,11 @@ if __name__ == '__main__': |
|
|
|
description = row.pop('description', None) |
|
|
|
description = row.pop('description', None) |
|
|
|
title = row.pop('title', None) |
|
|
|
title = row.pop('title', None) |
|
|
|
pk = row.pop('id', None) |
|
|
|
pk = row.pop('id', None) |
|
|
|
materials = [File.objects.get(id=i).key for i in row.pop('materials', None)] |
|
|
|
try: |
|
|
|
|
|
|
|
materials = [File.objects.get(id=i).key for i in row.pop('materials', None).split("[")[1].split("]")[0].split(", ")] |
|
|
|
|
|
|
|
except IndexError: |
|
|
|
|
|
|
|
materials = [] |
|
|
|
|
|
|
|
|
|
|
|
if model_type == 'topic': |
|
|
|
if model_type == 'topic': |
|
|
|
course = Course.objects.get(id=row.pop('course', None)) |
|
|
|
course = Course.objects.get(id=row.pop('course', None)) |
|
|
|
Topic.objects.create( |
|
|
|
Topic.objects.create( |
|
|
|
@ -58,9 +73,10 @@ if __name__ == '__main__': |
|
|
|
title=title, |
|
|
|
title=title, |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sort = 0 |
|
|
|
if model_type == 'tutorial': |
|
|
|
if model_type == 'tutorial': |
|
|
|
topic = Topic.objects.get(id=row.pop('parent', None)) |
|
|
|
topic = Topic.objects.get(id=row.pop('parent', None)) |
|
|
|
Vertex.objects.create( |
|
|
|
small_vertex=Vertex.objects.create( |
|
|
|
id=pk, |
|
|
|
id=pk, |
|
|
|
video=row.pop('video', None), |
|
|
|
video=row.pop('video', None), |
|
|
|
materials=materials, |
|
|
|
materials=materials, |
|
|
|
@ -68,10 +84,12 @@ if __name__ == '__main__': |
|
|
|
description=description, |
|
|
|
description=description, |
|
|
|
title=title, |
|
|
|
title=title, |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
PivotVertex.objects.create(map_course=map_obj, vertex=small_vertex, sort=sort) |
|
|
|
|
|
|
|
sort += 1 |
|
|
|
|
|
|
|
|
|
|
|
if model_type == 'task': |
|
|
|
if model_type == 'task': |
|
|
|
topic = Topic.objects.get(id=row.pop('parent', None)) |
|
|
|
topic = Topic.objects.get(id=row.pop('parent', None)) |
|
|
|
Vertex.objects.create( |
|
|
|
small_vertex=Vertex.objects.create( |
|
|
|
id=pk, |
|
|
|
id=pk, |
|
|
|
materials=materials, |
|
|
|
materials=materials, |
|
|
|
topic=topic, |
|
|
|
topic=topic, |
|
|
|
@ -79,6 +97,8 @@ if __name__ == '__main__': |
|
|
|
title=title, |
|
|
|
title=title, |
|
|
|
valid_type=1, |
|
|
|
valid_type=1, |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
PivotVertex.objects.create(map_course=map_obj, vertex=small_vertex, sort=sort) |
|
|
|
|
|
|
|
sort += 1 |
|
|
|
|
|
|
|
|
|
|
|
for course in Course.objects.all(): |
|
|
|
for course in Course.objects.all(): |
|
|
|
map_obj = CourseMap.objects.create(course=course) |
|
|
|
map_obj = CourseMap.objects.create(course=course) |
|
|
|
|