Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Изменение кнопки "Перепроверить компетенции" и сообщения при изменении компетенций #674

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 15 additions & 17 deletions src/bot/handlers/categories.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,6 @@
'После этого нажми "Готово 👌"'
)

text_chose_subcategory = (
"Чтобы мне было понятнее, с какими задачами ты готов помогать фондам, "
"отметь свои профессиональные компетенции (можно выбрать несколько). "
'После этого нажми "Назад ⬅️"'
)


@logger_decor
@registered_user_required
Expand Down Expand Up @@ -123,19 +117,12 @@ async def subcategories_callback(
update: Update,
context: ContextTypes.DEFAULT_TYPE,
ext_site_user: ExternalSiteUser,
category_service: CategoryService = Provide[Container.bot_services_container.bot_category_service],
user_service: UserService = Provide[Container.bot_services_container.bot_user_service],
):
query = update.callback_query
parent_id = int(context.match.group(1))
context.user_data["parent_id"] = parent_id
subcategories = await category_service.get_unarchived_subcategories(parent_id)
selected_categories = await user_service.get_user_categories(update.effective_user.id)

await query.message.edit_text(
text_chose_subcategory,
reply_markup=await get_subcategories_keyboard(parent_id, subcategories, selected_categories),
)
await _display_chose_subcategories_message(update, parent_id, selected_categories)


@logger_decor
Expand All @@ -144,11 +131,9 @@ async def select_subcategory_callback(
update: Update,
context: ContextTypes.DEFAULT_TYPE,
ext_site_user: ExternalSiteUser,
category_service: CategoryService = Provide[Container.bot_services_container.bot_category_service],
user_service: UserService = Provide[Container.bot_services_container.bot_user_service],
procharity_api: ProcharityAPI = Provide[Container.core_services_container.procharity_api],
):
query = update.callback_query
subcategory_id = int(context.match.group(1))
selected_categories = await user_service.get_user_categories(update.effective_user.id)

Expand All @@ -164,10 +149,23 @@ async def select_subcategory_callback(
await procharity_api.send_user_categories(user.external_user.external_id, selected_categories.keys())

parent_id = context.user_data["parent_id"]
await _display_chose_subcategories_message(update, parent_id, selected_categories)


async def _display_chose_subcategories_message(
update: Update,
parent_id: int,
selected_categories: dict[int, str],
category_service: CategoryService = Provide[Container.bot_services_container.bot_category_service],
) -> None:
"""Отображает сообщение с предложением выбрать подкатегории и кнопки подкатегорий."""
query = update.callback_query
parent = await category_service.get(parent_id, is_archived=None)
subcategories = await category_service.get_unarchived_subcategories(parent_id)
await query.message.edit_text(
text_chose_subcategory,
f'Ты выбрал категорию <b>"{parent.name}"</b>. Отметь любое количество компетенций и нажми "Назад ⬅️"',
reply_markup=await get_subcategories_keyboard(parent_id, subcategories, selected_categories),
parse_mode=ParseMode.HTML,
)


Expand Down
4 changes: 1 addition & 3 deletions src/bot/keyboards.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@
SUBSCRIBE_BUTTON = [InlineKeyboardButton("▶️ Подписаться на задания", callback_data=callback_data.JOB_SUBSCRIPTION)]
OPEN_MENU_BUTTON = [InlineKeyboardButton("Открыть меню", callback_data=callback_data.MENU)]
RETURN_MENU_BUTTON = [InlineKeyboardButton("Вернуться в меню", callback_data=callback_data.MENU)]
CHECK_CATEGORIES_BUTTON = [
InlineKeyboardButton("Перепроверить компетенции", callback_data=callback_data.CONFIRM_CATEGORIES)
]
CHECK_CATEGORIES_BUTTON = [InlineKeyboardButton("Проверить компетенции", callback_data=callback_data.VIEW_CATEGORIES)]
SHOW_MORE_TASKS_BUTTON = [InlineKeyboardButton("Показать ещё задания", callback_data=callback_data.VIEW_TASKS)]
SUPPORT_SERVICE_BUTTON = [
InlineKeyboardButton("✍ Написать в службу поддержки", callback_data=callback_data.SUPPORT_SERVICE)
Expand Down
3 changes: 3 additions & 0 deletions src/bot/services/category.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ class CategoryService:
def __init__(self, category_repository: CategoryRepository) -> None:
self._category_repository = category_repository

async def get(self, id: int, *, is_archived: bool | None = False) -> Category:
return await self._category_repository.get(id, is_archived=is_archived)

async def get_unarchived_subcategories(self, parent_id) -> list[Category]:
return await self._category_repository.get_unarchived_subcategories(parent_id)

Expand Down