Skip to content

Commit 5ecce9b

Browse files
style(Bot): Полировка кода
1 parent e4d3730 commit 5ecce9b

File tree

4 files changed

+20
-31
lines changed

4 files changed

+20
-31
lines changed

handlers/bot_routes/route_edit_items.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
"""Логика редактирования элементов карточки"""
22

3-
from aiogram import Router, types, F
3+
from aiogram import F, Router, types
44
from aiogram.utils.keyboard import InlineKeyboardBuilder
55

6-
from handlers.handler_nc_deck import update_card_description
7-
from handlers.bot_routes.states import CardCallback
6+
from handlers.bot_routes.route_list_cards import list_handler
87
from handlers.bot_routes.route_view_card import (
9-
get_cached_card,
108
_show_card_view,
9+
get_cached_card,
1110
)
12-
from handlers.bot_routes.route_list_cards import list_handler
13-
14-
# from handlers.handler_logging import logger
11+
from handlers.bot_routes.states import CardCallback
12+
from handlers.handler_logging import logger
13+
from handlers.handler_nc_deck import update_card_description
1514

1615
edit_router = Router()
1716

@@ -48,13 +47,15 @@ async def toggle_item_handler(
4847
success = await update_card_description(target_card.id, new_description)
4948

5049
if success:
50+
logger.success(f"Статус карочки {target_card.id} обновлен")
5151
await callback.answer("✅ Статус обновлен")
52-
# Обновляем кэш и показываем обновленную карточку
5352
target_card.description = new_description
5453
await _show_card_view(callback.message, target_card)
5554
else:
55+
logger.error(f"Статус карточки {target_card.id} не был обновлен")
5656
await callback.answer("❌ Ошибка обновления")
5757
else:
58+
logger.error(f"Элемент карточки {target_card.id} не был найден")
5859
await callback.answer("❌ Элемент не найден")
5960

6061

handlers/bot_routes/route_view_card.py

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,13 @@ async def _show_card_view(message: types.Message, card) -> None:
6969
for index, item in enumerate(items):
7070
description = card.description or ""
7171
lines = description.split("\n")
72-
EMOJI_CHECKED = "✅"
73-
EMOJI_UNCHECKED = "🔳"
72+
emoji_checked = "✅"
73+
emoji_unchecked = "🔘"
7474

7575
emoji = (
76-
EMOJI_CHECKED
76+
emoji_checked
7777
if index < len(lines) and "[x]" in lines[index]
78-
else EMOJI_UNCHECKED
78+
else emoji_unchecked
7979
)
8080

8181
display_item = item
@@ -184,16 +184,16 @@ async def _parse_new_items(text: str) -> list:
184184
:return: Список очищенных элементов
185185
:rtype: list
186186
"""
187-
ITEM_SEPARATOR = ","
187+
item_separator = ","
188188

189189
new_items_text = text.strip()
190190
if not new_items_text:
191191
return []
192192

193-
if ITEM_SEPARATOR in new_items_text:
193+
if item_separator in new_items_text:
194194
return [
195195
item.strip()
196-
for item in new_items_text.split(ITEM_SEPARATOR)
196+
for item in new_items_text.split(item_separator)
197197
if item.strip()
198198
]
199199
return [new_items_text]
@@ -213,20 +213,12 @@ async def _add_items_to_card(message: types.Message, card) -> None:
213213
return
214214

215215
logger.info(f"Парсинг элементов: {new_items}")
216-
217-
# Получаем текущие элементы с их состояниями
218216
current_items_with_states = card.get_list_items_with_states()
219217
current_item_texts = [item["text"] for item in current_items_with_states]
220-
221-
# Добавляем только новые элементы (исключаем дубликаты)
222218
for new_item in new_items:
223219
if new_item not in current_item_texts:
224220
current_items_with_states.append({"text": new_item, "checked": False})
225-
226-
# Создаем обновленный список текстов элементов для обновления
227221
updated_item_texts = [item["text"] for item in current_items_with_states]
228-
229-
# Обновляем описание карточки
230222
new_description = card.update_list_items(updated_item_texts)
231223

232224
logger.info(f"Обновление карточки {card.id}: {len(updated_item_texts)} элементов")
@@ -235,7 +227,6 @@ async def _add_items_to_card(message: types.Message, card) -> None:
235227

236228
if success:
237229
await message.answer(f"✅ Добавлено {len(new_items)} элементов в '{card.title}'")
238-
# Обновляем кэш
239230
card.description = new_description
240231
_card_cache[card.id] = card
241232
await list_handler(message)

handlers/handler_server.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ async def lifespan(_: FastAPI):
4646
logger.info("Сервер остановлен")
4747

4848

49-
# Создаем приложение с lifespan
5049
app = create_application()
5150
app.router.lifespan_context = lifespan
5251

models/model_card.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ class ModelCard(BaseModel):
2626
@property
2727
def short_title(self) -> str:
2828
"""Сокращенный заголовок для кнопок"""
29-
MAX_TITLE_LENGTH = 30
30-
ELLIPSIS_LENGTH = 3
29+
max_title_length = 30
30+
ellipsis_length = 3
3131

32-
if len(self.title) > MAX_TITLE_LENGTH:
33-
return self.title[: MAX_TITLE_LENGTH - ELLIPSIS_LENGTH] + "..."
32+
if len(self.title) > max_title_length:
33+
return self.title[: max_title_length - ellipsis_length] + "..."
3434
return self.title
3535

3636
def get_list_items(self) -> List[str]:
@@ -95,7 +95,6 @@ def update_list_items(self, items: List[str]) -> str:
9595
if not line:
9696
continue
9797

98-
# Определяем состояние элемента с помощью match case
9998
match line:
10099
case line if line.startswith("- [x] "):
101100
item_text = line[6:].strip()
@@ -141,7 +140,6 @@ def get_list_items_with_states(self) -> List[dict]:
141140
if not line:
142141
continue
143142

144-
# Определяем состояние элемента с помощью match case
145143
match line:
146144
case line if line.startswith("- [x] "):
147145
item_text = line[6:].strip()

0 commit comments

Comments
 (0)