diff --git a/app/admin.py b/app/admin.py index 87ff552..045ca0c 100644 --- a/app/admin.py +++ b/app/admin.py @@ -169,7 +169,7 @@ def council(request: Request, q: str = "", offset: int = 0, sort: str = "total_c authenticated = optional_user(request, settings, db) try: result = council_candidates(db, q=q, offset=offset, sort=sort, direction=direction, specialty=specialty, - branch=branch) + branch=branch, previous_specialty=request.query_params.get("previous_specialty")) except CouncilInputError as exc: return _render(request, "council.html", {"error": True, "public_page": True, "input_error": str(exc)}, status_code=422) except (SQLAlchemyError, OSError, ValueError, KeyError): @@ -303,7 +303,7 @@ def export_council(request: Request, q: str = "", sort: str = "total_count", dir db: Session = Depends(get_db)): try: result = council_candidates(db, q=q, sort=sort, direction=direction, paginate=False, specialty=specialty, - branch=branch) + branch=branch, previous_specialty=request.query_params.get("previous_specialty")) content = council_xlsx(result) except CouncilInputError as exc: return _render(request, "council.html", {"error": True, "public_page": True, "input_error": str(exc)}, status_code=422) diff --git a/app/services/council.py b/app/services/council.py index 5e4f37a..7e0c40b 100644 --- a/app/services/council.py +++ b/app/services/council.py @@ -253,7 +253,8 @@ def _unique_articles(articles: list[dict], start: date, end: date, corrections=N def council_candidates(db: Session, today: date | None = None, q: str = "", offset: int = 0, sort: str = "total_count", direction: str = "desc", paginate: bool = True, specialty: str = "", - branch: str = "технические", employee_id: int | None = None) -> dict: + branch: str = "технические", employee_id: int | None = None, + previous_specialty: str | None = None) -> dict: if branch and branch not in BRANCHES: raise CouncilInputError("Неизвестная отрасль науки") today = today or datetime.now(ZoneInfo("Europe/Moscow")).date() @@ -264,7 +265,12 @@ def council_candidates(db: Session, today: date | None = None, q: str = "", offs branches = list(dict.fromkeys(name for s in specialties if not specialty or s["code"] == specialty for name in s["branches"])) if branch and branch not in branches: - raise CouncilInputError("Отрасль оценки не относится к выбранным специальностям ВАК") + previous_branches = {name for s in specialties if previous_specialty == "" or s["code"] == previous_specialty + for name in s["branches"]} + if previous_specialty is not None and previous_specialty != specialty and branch in previous_branches: + branch = branches[0] + else: + raise CouncilInputError("Отрасль оценки не относится к выбранным специальностям ВАК") specialty_name = next((s["name"] for s in specialties if s["code"] == specialty), "") degree_sections = Employee.current_data["sections"] if db.get_bind().dialect.name == "postgresql": diff --git a/app/templates/council.html b/app/templates/council.html index fb40436..0484638 100644 --- a/app/templates/council.html +++ b/app/templates/council.html @@ -34,6 +34,7 @@