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.
43 lines
1.4 KiB
43 lines
1.4 KiB
import csv
|
|
import random
|
|
import string
|
|
|
|
import django
|
|
import os
|
|
import sys
|
|
|
|
from django.db import IntegrityError
|
|
|
|
sys.path.append("../")
|
|
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "lms.settings")
|
|
django.setup()
|
|
|
|
from storage.models import File
|
|
from access.models.progress import UserLessonAnswer, AnswerItem, ProgressLesson
|
|
|
|
if __name__ == '__main__':
|
|
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':
|
|
try:
|
|
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)),
|
|
)
|
|
except IntegrityError:
|
|
c = Comment.objects.get(id=row['id'])
|
|
|
|
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 = int(row['parent_id'])
|
|
if row['type'] == 'task':
|
|
parent_id += 50
|
|
|