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.
 
 
 
 
 
 

67 lines
2.2 KiB

from courses.models import Course, Lesson
class InApiTeacher:
@staticmethod
def add_teacher(slug: str, token: str) -> Course:
course = Course.objects.get(slug=slug)
course.teacher_tokens.append(token)
course.save()
return course
@staticmethod
def delete_teacher(slug: str, token: str) -> None:
course = Course.objects.get(slug=slug)
course.teacher_tokens.remove(token)
course.save()
@staticmethod
def get_token_list(slug: str) -> list:
return Course.objects.get(slug=slug).teacher_tokens
class CourseProgressApi:
@staticmethod
def get_topic_lesson(course_token: str):
course = Course.objects.get(token=course_token)
return [[lesson.token for lesson in topic.lesson_set.all()] for topic in course.topic_set.all()]
@staticmethod
def get_next(course_token: str, lesson_list: list):
"""
:param course_token:
:param lesson_list:
:return: следующий урок для прохождения и требует ли он валидации
"""
course = Course.objects.get(token=course_token)
acc = []
include_lesson = False
reversed_list = course.get_lesson_list()[::-1]
for lesson_idx, lesson in enumerate(reversed_list):
prev_idx = lesson_idx - 1
if include_lesson and not lesson.token in lesson_list:
acc.append((lesson.token, lesson.is_hm))
if lesson.token in lesson_list and not include_lesson:
acc.append((reversed_list[prev_idx].token, reversed_list[prev_idx].is_hm))
include_lesson = True
return acc
class CourseParamsApi:
def __init__(self, token):
self.__course = Course.objects.get(token=token)
def get_slug_and_title(self):
return {"title": self.__course.title, "slug": self.__course.slug}
def get_length(self):
return self.__course.topic_set.count()
def get_topic_by_lesson(self, lesson_token):
for idx, topic in enumerate(self.__course.topic_set.all()):
if topic.lesson_set.filter(token=lesson_token).exists():
return {"title": topic.title, "idx": idx}