Extend organization analytics contract and fix test warnings
Some checks failed
CI/CD Pipeline / Code Quality Checks (push) Failing after 1m42s
CI/CD Pipeline / Run Tests (push) Successful in 1m45s
CI/CD Pipeline / Build Docker Images (push) Has been skipped
CI/CD Pipeline / Push to Gitea Registry (push) Has been skipped
CI/CD Pipeline / Deploy to Server (push) Has been skipped

This commit is contained in:
2026-04-19 12:23:38 +02:00
parent f662e55139
commit 8ead5ebadc
14 changed files with 1348 additions and 130 deletions

View File

@@ -6,8 +6,14 @@ API ViewSets для организаций.
"""
from apps.core.viewsets import ClassicReadOnlyViewSet
from apps.organization.contract_serializers import (
OrganizationCatalogListResponseSerializer,
)
from apps.organization.models import Organization
from apps.organization.scope_utils import filter_queryset_by_scopes
from apps.organization.scope_utils import (
filter_queryset_by_registry_categories,
filter_queryset_by_scopes,
)
from apps.organization.serializers import (
OrganizationCatalogDetailSerializer,
OrganizationCatalogListSerializer,
@@ -15,6 +21,8 @@ from apps.organization.serializers import (
from apps.registers.models import RegistryMembershipPeriod
from django.db.models import Prefetch
from django_filters import rest_framework as filters
from drf_yasg import openapi
from drf_yasg.utils import swagger_auto_schema
from rest_framework.permissions import IsAuthenticated
@@ -26,6 +34,8 @@ class OrganizationFilter(filters.FilterSet):
ogrn = filters.CharFilter(lookup_expr="exact")
registry = filters.UUIDFilter(method="filter_registry")
corporation_scope = filters.CharFilter(method="filter_corporation_scope")
registry_category = filters.CharFilter(method="filter_registry_category")
registryCategory = filters.CharFilter(method="filter_registry_category")
organization_type = filters.CharFilter(lookup_expr="exact")
@staticmethod
@@ -44,6 +54,15 @@ class OrganizationFilter(filters.FilterSet):
return queryset
return filter_queryset_by_scopes(queryset, requested_scopes)
@staticmethod
def filter_registry_category(queryset, _name, value):
requested_categories = [
item.strip().lower() for item in str(value).split(",") if item.strip()
]
if not requested_categories:
return queryset
return filter_queryset_by_registry_categories(queryset, requested_categories)
class Meta:
model = Organization
fields = [
@@ -52,6 +71,7 @@ class OrganizationFilter(filters.FilterSet):
"ogrn",
"registry",
"corporation_scope",
"registry_category",
"organization_type",
]
@@ -79,6 +99,104 @@ class OrganizationViewSet(ClassicReadOnlyViewSet[Organization]):
"list": OrganizationCatalogListSerializer,
}
@swagger_auto_schema(
operation_summary="Список организаций",
operation_description=(
"Возвращает основной реестр организаций в paginated-форме "
"`count / next / previous / results`."
),
tags=["Организации"],
manual_parameters=[
openapi.Parameter(
"name",
openapi.IN_QUERY,
description="Фильтр по наименованию организации",
type=openapi.TYPE_STRING,
),
openapi.Parameter(
"inn",
openapi.IN_QUERY,
description="Фильтр по ИНН",
type=openapi.TYPE_STRING,
),
openapi.Parameter(
"ogrn",
openapi.IN_QUERY,
description="Фильтр по ОГРН",
type=openapi.TYPE_STRING,
),
openapi.Parameter(
"registry",
openapi.IN_QUERY,
description="ID активного реестра",
type=openapi.TYPE_STRING,
),
openapi.Parameter(
"corporation_scope",
openapi.IN_QUERY,
description="Код корпорации (`rosatom`, `roscosmos`, `opk`, `other`)",
type=openapi.TYPE_STRING,
),
openapi.Parameter(
"organization_type",
openapi.IN_QUERY,
description="Тип организации",
type=openapi.TYPE_STRING,
),
openapi.Parameter(
"registry_category",
openapi.IN_QUERY,
description=(
"Категория активного реестра для сайдбара "
"(`opk`, `goz`, `other`). Поддерживает список через запятую."
),
type=openapi.TYPE_STRING,
),
openapi.Parameter(
"registryCategory",
openapi.IN_QUERY,
description="CamelCase alias для `registry_category`.",
type=openapi.TYPE_STRING,
),
openapi.Parameter(
"search",
openapi.IN_QUERY,
description="Полнотекстовый поиск по name/short_name/inn/ogrn/okpo",
type=openapi.TYPE_STRING,
),
openapi.Parameter(
"ordering",
openapi.IN_QUERY,
description="Сортировка по `name`, `short_name`, `inn`, `created_at`",
type=openapi.TYPE_STRING,
),
openapi.Parameter(
"page",
openapi.IN_QUERY,
description="Номер страницы",
type=openapi.TYPE_INTEGER,
),
openapi.Parameter(
"page_size",
openapi.IN_QUERY,
description="Размер страницы",
type=openapi.TYPE_INTEGER,
),
],
responses={200: OrganizationCatalogListResponseSerializer},
)
def list(self, request, *args, **kwargs):
return super().list(request, *args, **kwargs)
@swagger_auto_schema(
operation_summary="Карточка организации",
operation_description="Возвращает детальную карточку организации.",
tags=["Организации"],
responses={200: OrganizationCatalogDetailSerializer},
)
def retrieve(self, request, *args, **kwargs):
return super().retrieve(request, *args, **kwargs)
def get_queryset(self):
return (
super()