diff --git a/app/services/admin_data.py b/app/services/admin_data.py index c167eb9..f66b98a 100644 --- a/app/services/admin_data.py +++ b/app/services/admin_data.py @@ -23,13 +23,17 @@ EMPLOYEE_SORTS = { _TRAINING_LABEL = "повышение квалификации" _TRAINING_KIND = re.compile(r",\s*повышение квалификации\s*(?:,|$)", re.IGNORECASE) +_TRAINING_MENTION = re.compile(r"\bповышени[еяю] квалификации\b", re.IGNORECASE) +_QUOTED_TEXT = re.compile(r'«[^»]*»|"[^"]*"') +_TRAINING_YEAR = re.compile(r"^(\d{4})(?!\d)|(? bool: for value in _as_list(data.get("sections")): section = _as_dict(value) - title = str(section.get("title") or "").casefold().strip() - if _TRAINING_LABEL not in (part.strip() for part in title.split("/")): + title = str(section.get("title") or "").casefold().strip().rstrip(":") + dedicated = title in {_TRAINING_LABEL, "курсы повышения квалификации"} + if not dedicated and _TRAINING_LABEL not in (part.strip() for part in title.split("/")): continue for value in _as_list(section.get("year_entries")): entry = _as_dict(value) @@ -37,7 +41,17 @@ def _has_training(data: dict[str, Any], since_year: int | None) -> bool: text = str(entry.get("text") or "").strip() if since_year is not None and (type(year) is not int or year < since_year): continue - if text and (title == _TRAINING_LABEL or _TRAINING_KIND.search(text)): + if text and text != str(year) and (dedicated or _TRAINING_KIND.search(_QUOTED_TEXT.sub("", text))): + return True + # Profiles may also list completed courses in manually entered paragraphs or lists. + for text in _clean_list(section.get("paragraphs")) + _clean_list(section.get("items")): + description = _QUOTED_TEXT.sub("", text).strip() + if not dedicated and not _TRAINING_MENTION.search(description): + continue + if since_year is None: + return True + match = _TRAINING_YEAR.search(description) + if match and int(match.group(1) or match.group(2)) >= since_year: return True return False diff --git a/app/static/admin.css b/app/static/admin.css index 3c9e0f5..37b33cd 100644 --- a/app/static/admin.css +++ b/app/static/admin.css @@ -795,6 +795,12 @@ font-weight: 700; } +@media (max-width: 1100px) { + .directory__filters { + grid-template-columns: repeat(3, minmax(0, 1fr)); + } +} + @media (max-width: 920px) { .directory__filters { grid-template-columns: 1fr 1fr; diff --git a/app/version.py b/app/version.py index 14ac4fa..4885a71 100644 --- a/app/version.py +++ b/app/version.py @@ -1,3 +1,3 @@ -APP_VERSION = "1.7.0" -FRONTEND_VERSION = "1.7.0" -BACKEND_VERSION = "1.7.0" +APP_VERSION = "1.7.1" +FRONTEND_VERSION = "1.7.1" +BACKEND_VERSION = "1.7.1" diff --git a/pyproject.toml b/pyproject.toml index b33a1a8..a83a7a8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "miem-workers" -version = "1.7.0" +version = "1.7.1" description = "MIEM employees parser, admin API, and web admin" requires-python = ">=3.11" dependencies = [ diff --git a/tests/test_api.py b/tests/test_api.py index d9c17df..5f11000 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -18,7 +18,7 @@ def test_health_returns_versions(): response = TestClient(app).get("/api/health") assert response.status_code == 200 - assert response.json()["backend_version"] == "1.7.0" + assert response.json()["backend_version"] == "1.7.1" def test_api_employees_and_stats_require_admin_session(): diff --git a/tests/test_council.py b/tests/test_council.py index f62d04a..8f63645 100644 --- a/tests/test_council.py +++ b/tests/test_council.py @@ -230,7 +230,7 @@ def test_public_page_data_minimization_and_safe_links(db_session, export): assert "javascript:" not in fragment.text and "private@example.org" not in fragment.text assert "javascript:" not in response.text and "private@example.org" not in response.text assert "/admin/employees/" not in response.text and "/admin/logout" not in response.text - assert "Backend 1.7.0 · Frontend 1.7.0" in response.text + assert "Backend 1.7.1 · Frontend 1.7.1" in response.text assert "Вход в систему" in response.text assert client.get("/admin/directory", follow_redirects=False).status_code in (302, 303, 401, 403) assert "Сотрудники не найдены" in client.get("/admin/council?q=missing").text diff --git a/tests/test_training_filter.py b/tests/test_training_filter.py index a193bf6..8e0da24 100644 --- a/tests/test_training_filter.py +++ b/tests/test_training_filter.py @@ -1,5 +1,6 @@ from bs4 import BeautifulSoup from fastapi.testclient import TestClient +import pytest from app.config import Settings, get_settings from app.db import get_db @@ -10,6 +11,37 @@ from app.security import SESSION_COOKIE, sign_session from app.services.admin_data import list_employees_page +@pytest.mark.parametrize( + ("html", "has_course", "has_recent_course"), + [ + ('

2024 (11 декабря), НИУ ВШЭ. Программа повышения квалификации «ИИ».

', True, True), + ('', True, True), + ('

Курсы повышения квалификации: «Технологии 2025 г.», 2023г.

', True, False), + ('

Программа повышения квалификации «Технологии 2025 г.»

', True, False), + ('

2025. Стажировка «Технологии».

', False, False), + ('

2025. Стажировка «Повышение квалификации педагогов».

', False, False), + ], +) +def test_training_filter_reads_courses_from_profile_paragraphs_and_lists( + db_session, html, has_course, has_recent_course, +): + url = "https://example.test/employee" + soup = BeautifulSoup( + f"

Дополнительное образование / Повышение квалификации / Стажировки

{html}
", + "html.parser", + ) + db_session.add(Employee( + profile_key="training:text", canonical_url=url, + current_data={"sections": extract_sections(soup, url)}, + )) + db_session.commit() + assert list_employees_page(db_session, has_training=True)["total"] == int(has_course) + assert list_employees_page(db_session, training_since_year=2024)["total"] == int(has_recent_course) + assert list_employees_page(db_session, training_since_year=2024, has_training=False)["total"] == int( + not has_recent_course + ) + + def test_training_filter_uses_course_year_and_kind_before_pagination(db_session): title = "Дополнительное образование / Повышение квалификации / Стажировки" profiles = [