Implement duty schedule import functionality and enhance user management
- Added a new command `/import_duty_schedule` for importing duty schedules via JSON, restricted to admin users. - Introduced a two-step import process: specifying handover time and uploading a JSON file. - Updated the database schema to allow `telegram_user_id` to be nullable for user creation by full name. - Implemented repository functions for user management, including `get_or_create_user_by_full_name` and `delete_duties_in_range`. - Enhanced README documentation with details on the new import command and JSON format requirements. - Added comprehensive tests for the duty schedule parser and integration tests for the import functionality.
This commit is contained in:
15
README.md
15
README.md
@@ -86,6 +86,21 @@ Ensure `.env` exists (e.g. `cp .env.example .env`) and contains `BOT_TOKEN`.
|
||||
|
||||
To add commands, define async handlers in `handlers/commands.py` (or a new module) and register them in `handlers/__init__.py`.
|
||||
|
||||
## Импорт расписания дежурств (duty-schedule)
|
||||
|
||||
Команда **`/import_duty_schedule`** доступна только пользователям из `ADMIN_USERNAMES`. Импорт выполняется в два шага:
|
||||
|
||||
1. **Время пересменки** — бот просит указать время и при необходимости часовой пояс (например `09:00 Europe/Moscow` или `06:00 UTC`). Время приводится к UTC и используется для границ смен при создании записей.
|
||||
2. **Файл JSON** — отправьте файл в формате duty-schedule (см. ниже).
|
||||
|
||||
Формат **duty-schedule**:
|
||||
- **meta**: обязательное поле `start_date` (YYYY-MM-DD), опционально `weeks`; количество дней определяется по длине строки `duty`.
|
||||
- **schedule**: массив объектов с полями:
|
||||
- `name` — ФИО (строка);
|
||||
- `duty` — строка с разделителем `;`: каждый элемент соответствует дню с `start_date` по порядку. Пусто или пробелы — нет дежурства; символы **б**, **Б**, **в**, **Н**, **О** — день дежурства.
|
||||
|
||||
При повторном импорте дежурства в том же диапазоне дат для каждого пользователя заменяются новыми.
|
||||
|
||||
## Tests
|
||||
|
||||
Install dev dependencies and run pytest:
|
||||
|
||||
Reference in New Issue
Block a user