parent
6a8cf139cf
commit
24737191c0
1 changed files with 38 additions and 3 deletions
@ -1,21 +1,56 @@ |
||||
import os, sys, django, csv |
||||
|
||||
from django.contrib.auth import get_user_model |
||||
|
||||
sys.path.append("../") |
||||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "lms.settings") |
||||
django.setup() |
||||
|
||||
from courses.models import Vertex |
||||
from django.contrib.contenttypes.models import ContentType |
||||
from journals.models import Thread, Journal |
||||
from storage.models import Storage |
||||
|
||||
if __name__ == '__main__': |
||||
csv.field_size_limit(500 * 1024 * 1024) |
||||
thread = Thread.objects.get(key='Student_teacher') |
||||
ct = ContentType.objects.get(app_label='courses', model='vertex') |
||||
with open('./management/comment.csv') as comment_csv: |
||||
comment_reader = csv.DictReader(comment_csv) |
||||
for row in comment_reader: |
||||
if row['type'] == 'task': |
||||
owner = get_user_model().objects.get(email=row['owner__email']) |
||||
sub = get_user_model().objects.get(email=row['sub__email']) |
||||
vertex = Vertex.objects.get(object_id=row['object_id'], content_type__model='task') |
||||
action = 0 |
||||
if row['status'] == "Одобрено": |
||||
print(row) |
||||
action = 1 |
||||
child_thread, is_create = Thread.objects.get_or_create( |
||||
key="""user_%s__staff_%s""" % (sub.id, owner.id,) |
||||
) |
||||
elif row['status'] == "Отклонено": |
||||
print(row) |
||||
action = 2 |
||||
child_thread, is_create = Thread.objects.get_or_create( |
||||
key="""user_%s__staff_%s""" % (sub.id, owner.id,) |
||||
) |
||||
else: |
||||
print(row) |
||||
child_thread, is_create = Thread.objects.get_or_create( |
||||
key="""user_%s__staff_%s""" % (owner.id, sub.id,) |
||||
) |
||||
|
||||
journal = Journal.objects.create( |
||||
thread=child_thread, |
||||
user=owner, |
||||
content_type=ct, |
||||
object_id=vertex.id, |
||||
action_type=action, |
||||
date=row['date'], |
||||
) |
||||
|
||||
for file_id in row['files']: |
||||
journal.files.add(Storage.objects.get(id=file_id)) |
||||
|
||||
if is_create: |
||||
child_thread.parent.add(thread) |
||||
child_thread.subscribers.add(owner) |
||||
child_thread.subscribers.add(sub) |
||||
|
||||
Loading…
Reference in new issue