async def courses(callback_query: CallbackQuery, user_data: Tuple[Campus, Peer, User]): await dp.current_state(user=callback_query.from_user.id ).set_state(States.THROTTLER) campus, _, user = user_data cursus_id = int(callback_query.data.split('.')[1]) back_button_data = (Config.local.back.get(user.language), 'back.courses') if user.use_default_campus: projects = await Project.get_projects(cursus_id=cursus_id) keyboard = data_keyboard(data=projects, action='projects', content=f'{cursus_id}={campus.id}', limit=30, back_button_data=back_button_data) text = Config.local.project_choose.get(user.language) else: campuses = await Campus.get_campuses() keyboard = data_keyboard(data=campuses, action='courses_campuses', content=cursus_id, limit=30, back_button_data=back_button_data) text = Config.local.campus_choose.get(user.language) await callback_query.answer() await dp.current_state(user=user.id).set_state(States.GRANTED) with suppress(MessageNotModified, MessageToEditNotFound): await callback_query.message.edit_text(text, reply_markup=keyboard)
async def projects_(callback_query: CallbackQuery, user_data: Tuple[Campus, Peer, User]): await dp.current_state(user=callback_query.from_user.id ).set_state(States.THROTTLER) *_, user = user_data content, project_id, page = callback_query.data.split('.')[1:] project_id = int(project_id) cursus_id, campus_id = map(int, content.split('=')) await callback_query.message.bot.send_chat_action(user.id, 'typing') text = await text_compile.project_peers_compile(user=user, project_id=project_id, campus_id=campus_id) projects = await Project.get_projects(cursus_id=cursus_id) back_button_data = (Config.local.back.get(user.language), 'back.courses') if not user.use_default_campus: back_button_data = (Config.local.back.get(user.language), f'back.courses.{cursus_id}') keyboard = data_keyboard(data=projects, action='projects', content=content, limit=30, current_id=project_id, page=int(page), back_button_data=back_button_data) await callback_query.answer() with suppress(MessageToDeleteNotFound, MessageCantBeDeleted): await callback_query.message.delete() await dp.current_state(user=user.id).set_state(States.GRANTED) await bot.send_message(user.id, text, reply_markup=keyboard)
async def free_locations(message: Message, user_data: Tuple[Campus, Peer, User]): await dp.current_state(user=message.from_user.id).set_state(States.THROTTLER) _, peer, user = user_data if user.use_default_campus: message = await message.answer(Config.local.wait.get(user.language)) await message.bot.send_chat_action(user.id, 'typing') text, count, _ = await text_compile.free_locations_compile(user=user, campus_id=peer.campus_id) keyboard = pagination_keyboard(action='locations_pagination', count=count, content=peer.campus_id, limit=40, stop=9) with suppress(MessageToDeleteNotFound, MessageCantBeDeleted): await message.delete() await bot.send_message(user.id, text, reply_markup=keyboard) else: campuses = await Campus.get_campuses() keyboard = data_keyboard(data=campuses, action='locations_campuses', content='locations', limit=30) await message.answer(Config.local.campus_choose.get(user.language), reply_markup=keyboard) await dp.current_state(user=user.id).set_state(States.GRANTED)
async def back_to_campuses(callback_query: CallbackQuery, user_data: Tuple[Campus, Peer, User]): await dp.current_state(user=callback_query.from_user.id ).set_state(States.THROTTLER) *_, user = user_data campuses = await Campus.get_campuses() action = { 'back.locations': 'locations_campuses', 'back.events': 'events_campuses' }[callback_query.data] keyboard = data_keyboard(data=campuses, action=action, content='locations', limit=30) await callback_query.answer() await dp.current_state(user=user.id).set_state(States.GRANTED) with suppress(MessageNotModified, MessageToEditNotFound): await callback_query.message.edit_text(Config.local.campus_choose.get( user.language), reply_markup=keyboard, disable_web_page_preview=True)
async def campuses_pagination(callback_query: CallbackQuery, user_data: Tuple[Campus, Peer, User]): await dp.current_state(user=callback_query.from_user.id ).set_state(States.THROTTLER) *_, user = user_data action = callback_query.data[:callback_query.data.rindex('_')] back_button_data = None if action == 'courses_campuses': back_button_data = (Config.local.back.get(user.language), 'back.courses') content, page = callback_query.data.split('.')[1:] campuses = await Campus.get_campuses() keyboard = data_keyboard(data=campuses, action=action, content=content, limit=30, page=int(page), back_button_data=back_button_data) await callback_query.answer() await dp.current_state(user=user.id).set_state(States.GRANTED) with suppress(MessageNotModified, MessageToEditNotFound): await callback_query.message.edit_reply_markup(reply_markup=keyboard)
async def projects_pagination(callback_query: CallbackQuery, user_data: Tuple[Campus, Peer, User]): await dp.current_state(user=callback_query.from_user.id ).set_state(States.THROTTLER) campus, _, user = user_data content, page = callback_query.data.split('.')[1:] cursus_id = int(content.split('=')[0]) projects = await Project.get_projects(cursus_id=cursus_id) back_button_data = (Config.local.back.get(user.language), 'back.courses') if not user.use_default_campus: back_button_data = (Config.local.back.get(user.language), f'back.courses.{cursus_id}') keyboard = data_keyboard(data=projects, action='projects', content=content, limit=30, page=int(page), back_button_data=back_button_data) await callback_query.answer() await dp.current_state(user=user.id).set_state(States.GRANTED) with suppress(MessageNotModified, MessageToEditNotFound): await callback_query.message.edit_text(Config.local.project_choose.get( user.language), reply_markup=keyboard)