feat(organization): scalar corporation_scope and scopes dictionary endpoint

This commit is contained in:
2026-04-14 10:41:12 +02:00
parent db64c9d2d9
commit 97e269fe1a
6 changed files with 129 additions and 6 deletions

View File

@@ -16,6 +16,21 @@ SCOPE_LABELS: dict[str, str] = {
"rosatom": "Госкорпорация «Росатом»",
"roscosmos": "Госкорпорация «Роскосмос»",
"opk": "Организации ОПК",
"other": "Иная корпорация",
}
SCOPE_SHORT_NAMES: dict[str, str] = {
"rosatom": "Росатом",
"roscosmos": "Роскосмос",
"opk": "ОПК",
"other": "Иная",
}
SCOPE_SORT_ORDER: dict[str, int] = {
"rosatom": 10,
"roscosmos": 20,
"opk": 30,
"other": 90,
}
@@ -38,6 +53,27 @@ def scope_labels(scope_codes: Iterable[str]) -> list[str]:
return [SCOPE_LABELS[code] for code in scope_codes if code in SCOPE_LABELS]
def get_corporation_scope_dictionary() -> list[dict[str, str | int]]:
"""Возвращает справочник корпусов для API-словаря."""
items: list[dict[str, str | int]] = []
for code, sort_order in sorted(
SCOPE_SORT_ORDER.items(), key=lambda item: item[1]
):
label = SCOPE_LABELS.get(code)
short_name = SCOPE_SHORT_NAMES.get(code)
if not label or not short_name:
continue
items.append(
{
"code": code,
"name": label,
"short_name": short_name,
"sort_order": sort_order,
}
)
return items
def build_scope_query(scope_codes: Iterable[str]) -> Q:
query = Q()
for scope_code in scope_codes: