Ejemplo n.º 1
0
async def faq_info_callback_handler(
    query: types.CallbackQuery,
    callback_data: typing.Dict[str, str],
    user: UserRepository,
    _: dict,
):
    question_id = int(callback_data["id"])
    page = callback_data['page']

    keyboard_markup = types.InlineKeyboardMarkup(row_width=2)

    me = await user.get_user(query.from_user.id)

    q_repo = QuestionRepository(user.connection)

    keyboard_markup.row(
        types.InlineKeyboardButton(
            _["faq_back_to_list"],
            callback_data=question_answer_cb.new(
                id="_",
                page=page,
                action="page",
            ),
        ), )

    question_answer = await q_repo.get_question_answers_by_lang_id_question_id(
        me.lang_id, question_id)

    await query.message.edit_text(
        question_answer.answer_text,
        reply_markup=keyboard_markup,
        disable_web_page_preview=True,
    )
    await query.answer()
Ejemplo n.º 2
0
    async def handle(self, message: types.Message, user: UserRepository,
                     _: dict):
        page = 1
        inline_keyboard_markup = types.InlineKeyboardMarkup(row_width=2)
        me = await user.get_user(message.from_user.id)

        q_repo = QuestionRepository(user.connection)

        questions = await q_repo.get_question_answers_enabled_by_lang_id(
            me.lang_id)
        for n, q in enumerate(questions[(page - 1) * PER_PAGE_FAQ:page *
                                        PER_PAGE_FAQ]):
            inline_keyboard_markup.row(
                types.InlineKeyboardButton(
                    f"#{(page - 1) * PER_PAGE_FAQ + n + 1} {q.question_text}",
                    callback_data=question_answer_cb.new(
                        id=q.id,
                        page=page,
                        action="open",
                    ),
                ), )

        buttons = []
        if (page > 1):
            buttons.append(
                types.InlineKeyboardButton(
                    _["prev_button"],
                    callback_data=question_answer_cb.new(
                        id="_",
                        page=page - 1,
                        action="page",
                    ),
                ), )

        if (questions):
            buttons.append(
                types.InlineKeyboardButton(
                    f"{page}/{ceil(len(questions) / PER_PAGE_FAQ)}",
                    callback_data="do_nothing"), )

        if (len(questions) > page * PER_PAGE_FAQ):
            buttons.append(
                types.InlineKeyboardButton(
                    _["next_button"],
                    callback_data=question_answer_cb.new(
                        id="_",
                        page=page + 1,
                        action="page",
                    ),
                ), )

        inline_keyboard_markup.row(*buttons)

        await message.answer(_['faq_msg_descr'],
                             reply_markup=inline_keyboard_markup)
Ejemplo n.º 3
0
async def delete_question(request: Request,
                          lang_id: int,
                          question_id: int,
                          Authorize: AuthJWT = Depends()):
    Authorize.jwt_required()

    question_repo = QuestionRepository(request.state.connection)

    await question_repo.delete(lang_id, question_id)

    return {}
Ejemplo n.º 4
0
async def get_question_list(request: Request, lang_id: int, Authorize: AuthJWT = Depends()):
    Authorize.jwt_required()

    question_repo = QuestionRepository(request.state.connection)
    
    questions = await question_repo.get_question_answers_by_lang_id(lang_id,)

    return [{
        'questionId': question.id,
        'langId': question.lang_id,
        'questionTranslation': question.question_text,
        'answerTranslation': question.answer_text,
        'statusId': question.status,
    } for question in questions]
Ejemplo n.º 5
0
Archivo: add.py Proyecto: Forevka/Emcd
async def add_question(request: Request,
                       questionAnswer: QuestionAnswer,
                       Authorize: AuthJWT = Depends()):
    Authorize.jwt_required()

    question_repo = QuestionRepository(request.state.connection)

    q_id = await question_repo.add_faq_answer(
        questionAnswer.langId, questionAnswer.questionTranslation,
        questionAnswer.answerTranslation)

    question = await question_repo.get_question_answers_by_lang_id_question_id(
        questionAnswer.langId, q_id)

    return {
        'questionId': q_id,
        'langId': question.lang_id,
        'questionTranslation': question.question_text,
        'answerTranslation': question.answer_text,
        'statusId': 1,
    }