|
|
|
@ -77,7 +77,7 @@ class CourseProgressUserView(APIView): |
|
|
|
return Response(status=403) |
|
|
|
return Response(status=403) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class UpdateProgress(APIView): |
|
|
|
class TeacherUpdateProgress(APIView): |
|
|
|
renderer_classes = (JSONRenderer,) |
|
|
|
renderer_classes = (JSONRenderer,) |
|
|
|
|
|
|
|
|
|
|
|
@staticmethod |
|
|
|
@staticmethod |
|
|
|
@ -90,13 +90,12 @@ class UpdateProgress(APIView): |
|
|
|
|
|
|
|
|
|
|
|
if lesson_token is None or course_token is None: |
|
|
|
if lesson_token is None or course_token is None: |
|
|
|
return Response('Не передан слаг курса или токен урока', status=400) |
|
|
|
return Response('Не передан слаг курса или токен урока', status=400) |
|
|
|
try: |
|
|
|
|
|
|
|
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: |
|
|
|
if student_out_key is None: |
|
|
|
p = Progress.objects.get(user=student, course_token=course_token) |
|
|
|
return Response('Не передан student_out_key', status=400) |
|
|
|
else: |
|
|
|
|
|
|
|
|
|
|
|
try: |
|
|
|
|
|
|
|
student = get_user_model().objects.get(out_key=student_out_key) |
|
|
|
p = Progress.objects.get( |
|
|
|
p = Progress.objects.get( |
|
|
|
user=student, |
|
|
|
user=student, |
|
|
|
teacher=request.user, |
|
|
|
teacher=request.user, |
|
|
|
@ -109,20 +108,7 @@ class UpdateProgress(APIView): |
|
|
|
lesson_token=lesson_token, |
|
|
|
lesson_token=lesson_token, |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
if is_student and not pv.status == ProgressLesson.STATUSES.wait \ |
|
|
|
if not pv.status == ProgressLesson.STATUSES.wait: |
|
|
|
and not pv.status == ProgressLesson.STATUSES.done: |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if pv.checker == p.teacher: |
|
|
|
|
|
|
|
pv.status = ProgressLesson.STATUSES.wait |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
elif pv.checker == p.user: |
|
|
|
|
|
|
|
pv.status = ProgressLesson.STATUSES.done |
|
|
|
|
|
|
|
pv.finish_date = datetime.datetime.now() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
else: |
|
|
|
|
|
|
|
raise ValueError("Этого никогда не должно происходить, но я уверен, что произойдёт") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
elif not is_student and pv.status == ProgressLesson.STATUSES.wait: |
|
|
|
|
|
|
|
if action == "no": |
|
|
|
if action == "no": |
|
|
|
pv.status = ProgressLesson.STATUSES.fail |
|
|
|
pv.status = ProgressLesson.STATUSES.fail |
|
|
|
|
|
|
|
|
|
|
|
@ -144,7 +130,62 @@ class UpdateProgress(APIView): |
|
|
|
pv.save() |
|
|
|
pv.save() |
|
|
|
|
|
|
|
|
|
|
|
res = {"current": ProgressLessonSerializer(pv).data} |
|
|
|
res = {"current": ProgressLessonSerializer(pv).data} |
|
|
|
if pv.status == ProgressLesson.STATUSES.done and not is_student: |
|
|
|
if pv.status == ProgressLesson.STATUSES.done: |
|
|
|
|
|
|
|
# TODO: Ассинхроннаязадача для celery |
|
|
|
|
|
|
|
res['next'] = add_next_lesson(p) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return Response(res, status=200) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
except Progress.DoesNotExist: |
|
|
|
|
|
|
|
return Response('Не найден прогресс по заданным параметрам', status=404) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class StudentUpdateProgress(APIView): |
|
|
|
|
|
|
|
renderer_classes = (JSONRenderer,) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@staticmethod |
|
|
|
|
|
|
|
def post(request): |
|
|
|
|
|
|
|
lesson_token = request.JSON.get('lesson_token', None) |
|
|
|
|
|
|
|
course_token = request.JSON.get('course_token', None) |
|
|
|
|
|
|
|
comment = request.JSON.get('comment', None) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if lesson_token is None or course_token is None: |
|
|
|
|
|
|
|
return Response('Не передан слаг курса или токен урока', status=400) |
|
|
|
|
|
|
|
try: |
|
|
|
|
|
|
|
student = request.user |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
p = Progress.objects.get(user=student, course_token=course_token) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try: |
|
|
|
|
|
|
|
pv = ProgressLesson.objects.get( |
|
|
|
|
|
|
|
progress=p, |
|
|
|
|
|
|
|
lesson_token=lesson_token, |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if not pv.status == ProgressLesson.STATUSES.wait \ |
|
|
|
|
|
|
|
and not pv.status == ProgressLesson.STATUSES.done: |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if pv.checker == p.teacher: |
|
|
|
|
|
|
|
pv.status = ProgressLesson.STATUSES.wait |
|
|
|
|
|
|
|
pv.comment_tokens.append(comment) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
elif pv.checker == p.user: |
|
|
|
|
|
|
|
pv.status = ProgressLesson.STATUSES.done |
|
|
|
|
|
|
|
pv.finish_date = datetime.datetime.now() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
else: |
|
|
|
|
|
|
|
raise ValueError("Этого никогда не должно происходить, но я уверен, что произойдёт") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pv.save() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
else: |
|
|
|
|
|
|
|
return Response("Ошибка прав доступа", status=403) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
except ProgressLesson.DoesNotExist: |
|
|
|
|
|
|
|
return Response('Урок не проходится этим пользователем', status=403) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
res = {"current": ProgressLessonSerializer(pv).data} |
|
|
|
|
|
|
|
if pv.status == ProgressLesson.STATUSES.done: |
|
|
|
# TODO: Ассинхроннаязадача для celery |
|
|
|
# TODO: Ассинхроннаязадача для celery |
|
|
|
res['next'] = add_next_lesson(p) |
|
|
|
res['next'] = add_next_lesson(p) |
|
|
|
|
|
|
|
|
|
|
|
|