Implement exchange imports and frontend reporting APIs
Some checks failed
CI/CD Pipeline / Code Quality Checks (push) Failing after 3m50s
CI/CD Pipeline / Run Tests (push) Successful in 3m57s
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
Some checks failed
CI/CD Pipeline / Code Quality Checks (push) Failing after 3m50s
CI/CD Pipeline / Run Tests (push) Successful in 3m57s
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:
@@ -2,20 +2,22 @@
|
||||
API ViewSets для организаций.
|
||||
|
||||
Содержит:
|
||||
- OrganizationViewSet - CRUD для организаций
|
||||
- OrganizationViewSet - frontend-facing read API for organizations.
|
||||
"""
|
||||
|
||||
from apps.core.viewsets import ReadOnlyViewSet
|
||||
from apps.organization.models import Organization
|
||||
from apps.organization.serializers import (
|
||||
OrganizationListSerializer,
|
||||
OrganizationSerializer,
|
||||
)
|
||||
from apps.registers.models import RegistryMembershipPeriod
|
||||
from django.db.models import Prefetch
|
||||
from django_filters import rest_framework as filters
|
||||
from rest_framework.permissions import IsAuthenticated
|
||||
|
||||
from apps.core.viewsets import ClassicReadOnlyViewSet
|
||||
from apps.organization.models import Organization
|
||||
from apps.organization.scope_utils import filter_queryset_by_scopes
|
||||
from apps.organization.serializers import (
|
||||
OrganizationCatalogDetailSerializer,
|
||||
OrganizationCatalogListSerializer,
|
||||
)
|
||||
from apps.registers.models import RegistryMembershipPeriod
|
||||
|
||||
|
||||
class OrganizationFilter(filters.FilterSet):
|
||||
"""Фильтры для организаций."""
|
||||
@@ -24,6 +26,8 @@ class OrganizationFilter(filters.FilterSet):
|
||||
inn = filters.CharFilter(lookup_expr="exact")
|
||||
ogrn = filters.CharFilter(lookup_expr="exact")
|
||||
registry = filters.UUIDFilter(method="filter_registry")
|
||||
corporation_scope = filters.CharFilter(method="filter_corporation_scope")
|
||||
organization_type = filters.CharFilter(lookup_expr="exact")
|
||||
|
||||
@staticmethod
|
||||
def filter_registry(queryset, _name, value):
|
||||
@@ -32,12 +36,28 @@ class OrganizationFilter(filters.FilterSet):
|
||||
membership_periods__ended_at__isnull=True,
|
||||
).distinct()
|
||||
|
||||
@staticmethod
|
||||
def filter_corporation_scope(queryset, _name, value):
|
||||
requested_scopes = [
|
||||
item.strip() for item in str(value).split(",") if item.strip()
|
||||
]
|
||||
if not requested_scopes:
|
||||
return queryset
|
||||
return filter_queryset_by_scopes(queryset, requested_scopes)
|
||||
|
||||
class Meta:
|
||||
model = Organization
|
||||
fields = ["name", "inn", "ogrn", "registry"]
|
||||
fields = [
|
||||
"name",
|
||||
"inn",
|
||||
"ogrn",
|
||||
"registry",
|
||||
"corporation_scope",
|
||||
"organization_type",
|
||||
]
|
||||
|
||||
|
||||
class OrganizationViewSet(ReadOnlyViewSet[Organization]):
|
||||
class OrganizationViewSet(ClassicReadOnlyViewSet[Organization]):
|
||||
"""
|
||||
ViewSet для просмотра организаций.
|
||||
|
||||
@@ -49,23 +69,17 @@ class OrganizationViewSet(ReadOnlyViewSet[Organization]):
|
||||
"""
|
||||
|
||||
queryset = Organization.objects.all()
|
||||
serializer_class = OrganizationSerializer
|
||||
serializer_class = OrganizationCatalogDetailSerializer
|
||||
permission_classes = [IsAuthenticated]
|
||||
filterset_class = OrganizationFilter
|
||||
search_fields = ["name", "inn", "ogrn"]
|
||||
ordering_fields = ["name", "inn", "created_at"]
|
||||
search_fields = ["name", "short_name", "inn", "ogrn", "okpo"]
|
||||
ordering_fields = ["name", "short_name", "inn", "created_at"]
|
||||
ordering = ["name"]
|
||||
|
||||
serializer_classes = {
|
||||
"list": OrganizationListSerializer,
|
||||
"list": OrganizationCatalogListSerializer,
|
||||
}
|
||||
|
||||
def get_serializer_class(self):
|
||||
"""Возвращает serializer в зависимости от action."""
|
||||
if self.action in self.serializer_classes:
|
||||
return self.serializer_classes[self.action]
|
||||
return super().get_serializer_class()
|
||||
|
||||
def get_queryset(self):
|
||||
return (
|
||||
super()
|
||||
|
||||
Reference in New Issue
Block a user