示例#1
0
async def delete_course(course_id: int, user: User):
    """Удаление курса."""
    course = await get_course_by_id(course_id)
    if not await is_course_teacher(course, user):
        raise exceptions.NotEnoughAccessRights()

    await course.delete()
示例#2
0
async def mark_solution(mark_data: dict, user: User):
    """Обработка JSON-запроса при оценке решения."""
    solution_id = mark_data["solutionId"]
    solution = await _get_solution_by_id(solution_id)
    if not await _is_solution_task_teacher(solution, user):
        raise exceptions.NotEnoughAccessRights()

    is_correct = mark_data["isCorrect"]
    solution.set_status(is_correct)
    await solution.save()
示例#3
0
async def create_course(course_data: dict, user: User) -> Course:
    """Создание нового курса."""
    if not user.is_authenticated or not user.is_teacher:
        raise exceptions.NotEnoughAccessRights()

    title = course_data["title"]
    description = course_data["description"]
    is_private = "isPrivate" in course_data
    course = await Course.create(
        title=title,
        description=description,
        is_private=is_private,
        teacher=user,
    )
    return course
示例#4
0
async def create_lesson(course_id: int, lesson_data: dict,
                        user: User) -> Lesson:
    """Создание нового урока в курсе."""
    course = await get_course_by_id(course_id)
    if not await is_course_teacher(course, user):
        raise exceptions.NotEnoughAccessRights()

    order_index = await _get_order_index(course)

    title = lesson_data["title"]
    lesson = await Lesson.create(
        title=title,
        order_index=order_index,
        course=course,
    )
    return lesson
示例#5
0
async def create_or_update_solution(task_id: int, solution_data: dict,
                                    user: User) -> TaskSolution:
    """Обработка запроса с решением задачи."""
    if not user.is_authenticated or user.is_teacher:
        raise exceptions.NotEnoughAccessRights()

    content = solution_data["content"].strip()
    extension = solution_data["extension"]
    task = await _get_task_by_id(task_id)

    solution, _ = await TaskSolution.update_or_create(
        defaults={
            "content": content,
            "extension": extension,
        },
        student=user,
        task=task,
    )
    return solution
示例#6
0
async def create_task(
    course_id: int, lesson_id: int, task_data: dict, user: User
) -> Task:
    """Создание задачи в уроке."""
    course = await get_course_by_id(course_id)
    if not await is_course_teacher(course, user):
        raise exceptions.NotEnoughAccessRights()

    lesson = await _get_lesson_by_id(lesson_id)
    order_index = await _get_order_index(lesson)

    title = task_data["title"]
    condition = task_data["condition"]
    example = task_data["example"]
    task = await Task.create(
        title=title,
        condition=condition,
        example=example,
        order_index=order_index,
        lesson=lesson,
    )
    return task
示例#7
0
async def _raise_for_solution_course_access(solution: TaskSolution,
                                            user: User):
    """Выбрасываем ошибку, если пользователь не является учителем курса."""
    if not await _is_solution_task_teacher(solution, user):
        raise exceptions.NotEnoughAccessRights()
示例#8
0
async def raise_for_course_access(course: Course, user: User):
    """Выбрасываем ошибку, если курс закрытый и пользователя в нём нет."""
    if course.is_private:
        await course.fetch_related("teacher", "students")
        if user != course.teacher and user not in course.students:
            raise exceptions.NotEnoughAccessRights()