diff --git a/app/belki/vk_bot.py b/app/belki/vk_bot.py index 77ba0c9..ba6d41c 100644 --- a/app/belki/vk_bot.py +++ b/app/belki/vk_bot.py @@ -85,8 +85,11 @@ def parse_text_command(text: str) -> dict[str, Any]: raise ValueError("Формат: /лу ДД.ММ HH:MM HH:MM | Имя [ID] | Котёнок [ID] | статус") date, start, end = parts[0].split() escort_name, escort_id = _person(parts[1]) - kitten_name, kitten_id = _person(parts[2]) - extras = [] + kitten_entries = [_person(item) for item in parts[2].split(",") if item.strip()] + if not kitten_entries: + raise ValueError("Укажите имя котёнка или котят через запятую в формате Имя [ID].") + kitten_name, kitten_id = kitten_entries[0] + extras = [(name, kitten_id, "самостоятельно") for name, kitten_id in kitten_entries[1:]] status_part = parts[3] if len(parts) > 3 else "" status_value = status_part.lower() status_is_valid = status_value in ("сам", "самостоятельно", "несам", "несамостоятельно") @@ -417,7 +420,7 @@ class BelkiDialog: ("start", "Укажите время начала в формате HH:MM."), ("end", "Укажите время конца (конец захода) в формате HH:MM."), ("escort", "Укажите сопровождающего в формате Имя [ID]."), - ("kitten", "Укажите котёнка в формате Имя [ID]."), + ("kitten", "Укажите имя котёнка или котят через запятую в формате Имя [ID].\nНапример: Беззубик [1566767], Малыш [123456]."), ("independence", "Котёнок самостоятельный или несамостоятельный?"), ), "training": ( @@ -730,7 +733,12 @@ class BelkiDialog: state[key] = True elif key == "kitten": try: - state["kitten_name"], state["kitten_id"] = _person(text) + kittens = [_person(item) for item in text.split(",") if item.strip()] + if not kittens: + raise ValueError("Укажите имя котёнка или котят через запятую в формате Имя [ID].") + state["kitten_name"], state["kitten_id"] = kittens[0] + if state.get("mode") == "coaching" and len(kittens) > 1: + state["extra_kittens"] = [(*item, "самостоятельно") for item in kittens[1:]] except ValueError as exc: return str(exc) state[key] = True diff --git a/app/main.py b/app/main.py index 3562c51..1734320 100644 --- a/app/main.py +++ b/app/main.py @@ -61,7 +61,11 @@ class Handler(BaseHTTPRequestHandler): query = parse_qs(urlparse(self.path).query) sort_by = query.get("sort", ["escort_id"])[0] descending = query.get("direction", ["desc"])[0] != "asc" - self._json(200, {"items": history_store().list_calculations(sort_by=sort_by, descending=descending)}) + try: + limit = int(query.get("limit", ["100"])[0]) + except ValueError: + limit = 100 + self._json(200, {"items": history_store().list_calculations(sort_by=sort_by, descending=descending, limit=limit)}) return requested = unquote(path).lstrip("/") candidate = (WEB_ROOT / requested).resolve() diff --git a/structure_and_data.md b/structure_and_data.md index 1fce0a9..e911330 100644 --- a/structure_and_data.md +++ b/structure_and_data.md @@ -27,6 +27,7 @@ - Every confirmed calculation is persisted by `app/belki/history.py` to PostgreSQL from `BELKI_DATABASE_URL`; SQLite is only a local fallback. Records include actor, source, mode, input, result, rendered message, and timestamp. - VK photo attachments received during an active dialog are normalized into `input.attachments` and persisted with the calculation; active reports attach photos immediately and deduplicate repeated VK events. `/admin` renders all thumbnails in a wrapped gallery. With `BELKI_IMAGE_HOST_API_URL`, the bot mirrors each photo through image-hosting-web and stores `mirror_url`; Google Sheets export remains deferred. - `/admin` and `/api/admin/calculations` expose the calculation history for review. The table shows both the reporting cat (escort) and kitten; default sorting is by the reporting cat, with optional kitten sorting. The API requires `X-Admin-Password` matching `BELKI_ADMIN_PASSWORD`; the web page supports deleting individual records through authenticated `DELETE /api/admin/calculations/{id}`, with confirmation in the UI. +- The admin page uses a restrained light editorial table layout with a separate password gate, responsive filters, client-side sorting across every visible column, cat/kitten selectors, sticky headings, and a keyboard-navigable photo gallery; behavior remains backed by the existing history API. - VK `messages.send` responses include a serialized context-aware keyboard; button payloads are translated back into the same dialog commands, while text commands remain supported. - Production k3s deployment (2026-08-16): namespace `belki` runs the Belki web calculator, VK bot, PostgreSQL 16, and the migrated cwshed Nginx gateway. The gateway keeps MetalLB IP `10.12.0.204`, serves the legacy CatWar site, and routes `/belki`, `/admin`, and `/api/*` to Belki web on `10.12.0.212`. Belki images are `reg.nyan404.ru/cwshed-clone/belki` and `reg.nyan404.ru/cwshed`; PostgreSQL is mirrored as `reg.nyan404.ru/library/postgres:16-alpine-amd64` because cluster nodes cannot pull Docker Hub directly. Registry pull credentials and runtime secrets are created out-of-band in the `belki` namespace. - The previously inspected `stage-zone-runner` at `10.3.1.236` is not the runner used by the current pipeline. Runner `#2` (`Ryzen-builder`) at `10.3.1.168` is a privileged Docker executor and supports the DinD service used by `.gitlab-ci.yml`. diff --git a/tests/test_vk_conversation.py b/tests/test_vk_conversation.py index dbfad7a..0a1874b 100644 --- a/tests/test_vk_conversation.py +++ b/tests/test_vk_conversation.py @@ -32,6 +32,15 @@ class VkConversationTests(unittest.TestCase): report = dialog.handle(77, "да") self.assertIn("Баллы белки: 4 баллы.", report) + def test_step_by_step_coaching_accepts_comma_separated_kittens(self): + dialog = BelkiDialog() + dialog.handle(78, "/лу") + for answer in ("15.08", "11:00", "11:20", "Белка [1]"): + dialog.handle(78, answer) + response = dialog.handle(78, "Беззубик [1566767], Малыш [123456]") + self.assertIn("самостоятель", response.lower()) + self.assertEqual(dialog._states[78]["extra_kittens"], [("Малыш", 123456, "самостоятельно")]) + def test_bulk_input_is_detected_and_confirmed(self): dialog = BelkiDialog() confirmation = dialog.handle( diff --git a/web/admin.html b/web/admin.html index 9e1c48e..775f2cd 100644 --- a/web/admin.html +++ b/web/admin.html @@ -5,88 +5,138 @@ Беличья нора — админка
-

Беличья нора — админская

-

История подтверждённых расчётов из VK-бота и веб-калькулятора.

-
- - - - -
-

-
ID записиАвторРежимКотКотёнокФотоДатаСообщениеДействие
+
+

Админская панель

+

Введите пароль администратора, чтобы открыть историю отчётов.

+
+ + +
+
+ +
+ + + + + +