feat(organization): scalar corporation_scope and scopes dictionary endpoint
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
"""
|
||||
|
||||
from apps.organization.models import Organization
|
||||
from apps.organization.scope_utils import SCOPE_LABELS
|
||||
from apps.registers.models import Register
|
||||
from rest_framework import serializers
|
||||
|
||||
@@ -108,12 +109,25 @@ class OrganizationCatalogBaseSerializer(serializers.ModelSerializer):
|
||||
return obj.get_active_registry_names()
|
||||
|
||||
@staticmethod
|
||||
def get_corporation_scope(obj: Organization) -> list[str]:
|
||||
return obj.get_corporation_scopes()
|
||||
def _primary_scope_or_default(obj: Organization) -> str:
|
||||
scopes = obj.get_corporation_scopes()
|
||||
return scopes[0] if scopes else ""
|
||||
|
||||
@staticmethod
|
||||
def get_corporation_scope_label(obj: Organization) -> list[str]:
|
||||
return obj.get_corporation_scope_labels()
|
||||
def get_corporation_scope(obj: Organization) -> str:
|
||||
return OrganizationCatalogBaseSerializer._primary_scope_or_default(obj)
|
||||
|
||||
@staticmethod
|
||||
def get_corporation_scope_label(obj: Organization) -> str:
|
||||
scope = OrganizationCatalogBaseSerializer._primary_scope_or_default(obj)
|
||||
return OrganizationCatalogBaseSerializer._label_or_empty(scope)
|
||||
|
||||
@staticmethod
|
||||
def _label_or_empty(scope_code: str) -> str:
|
||||
if not scope_code:
|
||||
return ""
|
||||
return SCOPE_LABELS.get(scope_code, "")
|
||||
|
||||
|
||||
|
||||
class OrganizationCatalogListSerializer(OrganizationCatalogBaseSerializer):
|
||||
@@ -193,3 +207,12 @@ class OrganizationCatalogDetailSerializer(OrganizationCatalogBaseSerializer):
|
||||
"created_at",
|
||||
"updated_at",
|
||||
]
|
||||
|
||||
|
||||
class CorporationScopeDictionarySerializer(serializers.Serializer):
|
||||
"""Serializer for corporation scope dictionary entries."""
|
||||
|
||||
code = serializers.CharField()
|
||||
name = serializers.CharField()
|
||||
short_name = serializers.CharField()
|
||||
sort_order = serializers.IntegerField()
|
||||
|
||||
Reference in New Issue
Block a user