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.
52 lines
1.6 KiB
52 lines
1.6 KiB
import csv
|
|
import random
|
|
import string
|
|
|
|
import django
|
|
import os
|
|
import sys
|
|
|
|
from django.contrib.auth import get_user_model
|
|
|
|
sys.path.append("../")
|
|
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "lms.settings")
|
|
django.setup()
|
|
|
|
from course_service.courses.models import Vertex
|
|
from storage.models import Comment, File
|
|
from access.models.other import PivotProgressVertex
|
|
|
|
if __name__ == '__main__':
|
|
Comment.objects.all().delete()
|
|
csv.field_size_limit(500 * 1024 * 1024)
|
|
with open('./management/comment.csv') as comment_csv:
|
|
comment_reader = csv.DictReader(comment_csv)
|
|
for row in comment_reader:
|
|
if row['type'] == 'task' or row['type'] == 'exam':
|
|
c = Comment.objects.create(
|
|
id=row['id'],
|
|
email=row['owner__email'],
|
|
text=row['text'],
|
|
key=''.join(random.choice(string.ascii_letters) for x in range(15)),
|
|
)
|
|
|
|
for file_id in row['files'].split("[")[1].split("]")[0].split(", "):
|
|
if file_id:
|
|
c.files.add(File.objects.get(id=file_id))
|
|
|
|
c.date = row['date']
|
|
c.save()
|
|
|
|
parent_id = row['parent_id']
|
|
if row['type'] == 'task':
|
|
parent_id += 50
|
|
|
|
vertex = Vertex.objects.get(id=parent_id)
|
|
vertex_key = vertex.token
|
|
comment_key = c.key
|
|
|
|
PivotProgressVertex.objects.get_or_create(
|
|
comment=comment_key,
|
|
vertex=vertex_key,
|
|
progress=vertex.topic.course.route.out_key
|
|
)
|
|
|