|
|
|
|
@ -20,6 +20,7 @@ from access.models.progress import ProgressLesson |
|
|
|
|
from access.models import Progress |
|
|
|
|
from access.serializers import UserSelfSerializer, UserSearchSerializer, ProgressLessonSerializer, \ |
|
|
|
|
ProgressAnalyticSerializer |
|
|
|
|
from access.tasks import add_next_lesson |
|
|
|
|
from courses.api import CourseProgressApi |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -246,33 +247,60 @@ class UpdateProgress(APIView): |
|
|
|
|
""" |
|
|
|
|
lesson_token = request.JSON.get('lesson_token', None) |
|
|
|
|
course_token = request.JSON.get('course_token', None) |
|
|
|
|
student_out_key = request.JSON.get('student_out_key', None) |
|
|
|
|
action = request.JSON.get('action', 'wait') |
|
|
|
|
comment = request.JSON.get('comment', None) |
|
|
|
|
|
|
|
|
|
if lesson_token is None or course_token is None: |
|
|
|
|
return Response('Не передан слаг курса или токен урока', status=400) |
|
|
|
|
try: |
|
|
|
|
p = Progress.objects.get(user=request.user, course_token=course_token) |
|
|
|
|
is_student = student_out_key is None |
|
|
|
|
student = request.user if is_student else get_user_model().objects.get(out_key=student_out_key) |
|
|
|
|
|
|
|
|
|
if is_student: |
|
|
|
|
p = Progress.objects.get(user=student, course_token=course_token) |
|
|
|
|
else: |
|
|
|
|
p = Progress.objects.get( |
|
|
|
|
user=student, |
|
|
|
|
teacher=request.user, |
|
|
|
|
course_token=course_token, |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
if p.active_lesson == lesson_token: |
|
|
|
|
return Response("Ошибка доступа", status=403) |
|
|
|
|
|
|
|
|
|
try: |
|
|
|
|
pv = ProgressLesson.objects.get( |
|
|
|
|
progress=p, |
|
|
|
|
lesson_token=lesson_token, |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
if is_student and pv.status == ProgressLesson.STATUSES.fail and action == "wait": |
|
|
|
|
pv.status = ProgressLesson.STATUSES.wait |
|
|
|
|
|
|
|
|
|
elif not is_student and pv.status == ProgressLesson.STATUSES.wait: |
|
|
|
|
pv.status = action |
|
|
|
|
|
|
|
|
|
else: |
|
|
|
|
return Response("Ошибка прав доступа", status=403) |
|
|
|
|
|
|
|
|
|
pv.comment_tokens.append(comment) |
|
|
|
|
|
|
|
|
|
except ProgressLesson.DoesNotExist: |
|
|
|
|
pv = ProgressLesson.objects.create( |
|
|
|
|
date=datetime.datetime.now(), |
|
|
|
|
teacher=p.teacher, |
|
|
|
|
progress=p, |
|
|
|
|
lesson_token=lesson_token, |
|
|
|
|
status=ProgressLesson.STATUSES.done |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
if not comment is None: |
|
|
|
|
pv.comment_tokens.append(comment) |
|
|
|
|
pv.save() |
|
|
|
|
|
|
|
|
|
else: |
|
|
|
|
pv.status = ProgressLesson.STATUSES.done |
|
|
|
|
if pv.status == ProgressLesson.STATUSES.done: |
|
|
|
|
#TODO: Ассинхроннаязадача для celery |
|
|
|
|
add_next_lesson(p) |
|
|
|
|
|
|
|
|
|
pv.save() |
|
|
|
|
return Response(ProgressLessonSerializer(pv).data, status=200) |
|
|
|
|
|
|
|
|
|
except Progress.DoesNotExist: |
|
|
|
|
|