Пример #1
0
async def handle_create_course(request: Request) -> Response:
    """Обработка данных для создания курса."""
    course_data = await request.post()
    user = await get_current_user(request)

    try:
        course = await create_course(course_data, user)
    except exceptions.NotEnoughAccessRights:
        route = get_route(request, "create_course")
        return web.HTTPFound(location=route)
    else:
        route = get_route(request, "course", course_id=str(course.id))
        return web.HTTPFound(location=route)
Пример #2
0
async def handle_login(request: Request) -> Response:
    """Обработка данных для входа в аккаунт."""
    try:
        form_data = await request.post()
        email = form_data["email"]
        password = form_data["password"]
        route = get_route(request, "index")
        user = await get_user(email, password)
    except (exceptions.IncorrectPassword, exceptions.UserDoesNotExist):
        route = get_route(request, "login")
        return web.HTTPFound(location=route)
    else:
        redirect_response = web.HTTPFound(location=route)
        await remember(request, redirect_response, str(user.id))
        return redirect_response
Пример #3
0
async def login(request: Request) -> Response:
    """Страница входа в аккаунт."""
    user = await get_current_user(request)
    if user.is_authenticated:
        route = get_route(request, "index")
        return web.HTTPFound(location=route)
    return {"user": user}
Пример #4
0
async def profile(request: Request) -> Response:
    """Страница пользователя."""
    user = await get_current_user(request)
    if not user.is_authenticated:
        route = get_route(request, "register")
        return web.HTTPFound(location=route)
    return {"user": user}
Пример #5
0
async def activate_course_invite(request: Request) -> Response:
    """Страница активации пригласительного токена."""
    user = await get_current_user(request)
    if not user.is_authenticated or user.is_teacher:
        route = get_route(request, "index")
        return web.HTTPFound(location=route)

    return {"user": user}
def application(environ, start_response):
    p = Product()
    path = environ.get('PATH_INFO', '').lstrip('/')
    callback = get_route(path, urls)
    if callback:
        return callback(environ, start_response, p).serve()
    else:
        return NotFound(environ, start_response, p).serve()
Пример #7
0
async def create_course_form(request: Request) -> Response:
    """Создание курса."""
    user = await get_current_user(request)
    if not user.is_authenticated or not user.is_teacher:
        route = get_route(request, "index")
        return web.HTTPFound(location=route)

    return {"user": user}
Пример #8
0
async def register(request: Request) -> Response:
    """Страница регистрации."""
    user = await get_current_user(request)
    if user.is_authenticated:
        route = get_route(request, "index")
        return web.HTTPFound(location=route)

    return {"user": user}
Пример #9
0
async def handle_create_lesson(request: Request) -> Response:
    """Обработка данных для создания нового урока."""
    course_id = request.match_info["course_id"]
    lesson_data = await request.post()
    user = await get_current_user(request)

    try:
        lesson = await create_lesson(course_id, lesson_data, user)
    except exceptions.NotEnoughAccessRights:
        route = get_route(request, "create_course")
        return web.HTTPFound(location=route)
    else:
        route = get_route(
            request,
            "lesson",
            course_id=course_id,
            lesson_id=str(lesson.id),
        )
        return web.HTTPFound(location=route)
Пример #10
0
async def create_lesson_form(request: Request) -> Response:
    """Создание нового урока в курсе."""
    user = await get_current_user(request)
    course_id = request.match_info["course_id"]
    course = await get_course_by_id(course_id)
    if not await is_course_teacher(course, user):
        route = get_route(request, "index")
        return web.HTTPFound(location=route)

    return {"user": user, "course_id": course_id}
Пример #11
0
async def handle_create_task(request: Request) -> Response:
    """Обработка данных для создания новой задачи."""
    course_id = request.match_info["course_id"]
    lesson_id = request.match_info["lesson_id"]
    task_data = await request.post()
    user = await get_current_user(request)

    try:
        task = await create_task(course_id, lesson_id, task_data, user)
    except exceptions.NotEnoughAccessRights:
        route = get_route(request, "index")
        return web.HTTPFound(location=route)
    else:
        route = get_route(
            request,
            "task",
            course_id=course_id,
            lesson_id=lesson_id,
            task_id=str(task.id),
        )
        return web.HTTPFound(location=route)
Пример #12
0
async def handle_delete_course(request: Request) -> Response:
    """Обработка запроса на удаление курса."""
    course_id = request.match_info["course_id"]
    user = await get_current_user(request)

    try:
        await delete_course(course_id, user)
    except exceptions.NotEnoughAccessRights:
        ...
    else:
        route = get_route(request, "index")
        return web.HTTPFound(location=route)
Пример #13
0
def make_register_confirm_url(request: Request, token: str) -> str:
    """Создание ссылки для подтверждения регистрации."""
    route = get_route(request, "handle_register_token", token=token)
    confirm_url = f"{request.scheme}://{request.host}{route}"
    return confirm_url
Пример #14
0
def get_cost_latest(departure_time, departure, destination):
    sec = get_route(departure, destination,
                    departure_time)[0]['legs'][0]['duration']['value']
    return math.ceil(sec / 60)