fix - show org type by binary childs

This commit is contained in:
2025-11-04 11:59:20 +03:30
parent bcc9bac5fc
commit 95921aa8b4
4 changed files with 43 additions and 4 deletions

View File

@@ -207,7 +207,7 @@ class ProvinceViewSet(SoftDeleteMixin, ModelViewSet):
serializer_class = ProvinceSerializer serializer_class = ProvinceSerializer
class OrganizationTypeViewSet(SoftDeleteMixin, ModelViewSet): class OrganizationTypeViewSet(BaseViewSet, SoftDeleteMixin, ModelViewSet):
""" Crud operations for Organization Type model """ # """ Crud operations for Organization Type model """ #
queryset = OrganizationType.objects.all() queryset = OrganizationType.objects.all()
serializer_class = OrganizationTypeSerializer serializer_class = OrganizationTypeSerializer

View File

@@ -1,6 +1,6 @@
import typing import typing
from apps.authentication.models import Organization from apps.authentication.models import Organization, OrganizationType
def get_users_of_organization(org: Organization) -> typing.Any: def get_users_of_organization(org: Organization) -> typing.Any:
@@ -28,3 +28,15 @@ def get_all_org_child(org: Organization = None) -> typing.Any:
descendants.append(child) descendants.append(child)
descendants.extend(get_all_org_child(child)) descendants.extend(get_all_org_child(child))
return descendants return descendants
def get_all_org_type_child(org_type: OrganizationType = None) -> typing.Any:
"""
get all child of an organization
"""
descendants = []
children = org_type.children.all()
for child in children:
descendants.append(child)
descendants.extend(get_all_org_type_child(child))
return descendants

View File

@@ -1,7 +1,7 @@
from rest_framework import viewsets from rest_framework import viewsets
from apps.authentication.mixins.region_filter import RegionFilterMixin, get_organization_by_user from apps.authentication.mixins.region_filter import RegionFilterMixin, get_organization_by_user
from apps.authentication.services.service import get_all_org_child from apps.authentication.services.service import get_all_org_child, get_all_org_type_child
from apps.authentication.services.visibility_services import apply_visibility_filter from apps.authentication.services.visibility_services import apply_visibility_filter
from apps.authorization.services.role_child import get_all_role_child from apps.authorization.services.role_child import get_all_role_child
from apps.core.models import MobileTest, SystemConfig from apps.core.models import MobileTest, SystemConfig
@@ -50,9 +50,12 @@ class BaseViewSet(RegionFilterMixin, viewsets.ModelViewSet):
elif model_name == 'organization': elif model_name == 'organization':
queryset = queryset.filter(id__in=[org.id for org in child_orgs]) queryset = queryset.filter(id__in=[org.id for org in child_orgs])
elif model_name == 'organizationtype': # noqa
queryset = queryset.filter(id__in=[org_type.id for org_type in get_all_org_type_child(org.type)])
elif model_name == 'role': elif model_name == 'role':
queryset = queryset.filter(id__in=[role.id for role in get_all_role_child(user_relation.role)]) queryset = queryset.filter(id__in=[role.id for role in get_all_role_child(user_relation.role)])
return queryset return queryset

View File

@@ -1228,3 +1228,27 @@ TypeError: 'NoneType' object is not iterable
[2025-11-04 11:33:45,466] INFO django.utils.autoreload | IP: - | Path: - | D:\Project\Rasaddam_Backend\apps\authentication\api\v1\serializers\serializer.py changed, reloading. [2025-11-04 11:33:45,466] INFO django.utils.autoreload | IP: - | Path: - | D:\Project\Rasaddam_Backend\apps\authentication\api\v1\serializers\serializer.py changed, reloading.
[2025-11-04 11:33:49,074] INFO django.utils.autoreload | IP: - | Path: - | Watching for file changes with StatReloader [2025-11-04 11:33:49,074] INFO django.utils.autoreload | IP: - | Path: - | Watching for file changes with StatReloader
[2025-11-04 11:33:54,631] INFO django.server | IP: - | Path: - | "GET /auth/api/v1/user-relations/?role= HTTP/1.1" 200 17248 [2025-11-04 11:33:54,631] INFO django.server | IP: - | Path: - | "GET /auth/api/v1/user-relations/?role= HTTP/1.1" 200 17248
[2025-11-04 11:51:04,464] INFO django.utils.autoreload | IP: - | Path: - | D:\Project\Rasaddam_Backend\apps\authentication\services\service.py changed, reloading.
[2025-11-04 11:51:06,283] INFO django.utils.autoreload | IP: - | Path: - | Watching for file changes with StatReloader
[2025-11-04 11:51:14,527] INFO django.utils.autoreload | IP: - | Path: - | D:\Project\Rasaddam_Backend\apps\authentication\services\service.py changed, reloading.
[2025-11-04 11:51:16,895] INFO django.utils.autoreload | IP: - | Path: - | Watching for file changes with StatReloader
[2025-11-04 11:52:11,897] WARNING django.request | IP: 127.0.0.1 | Path: /auth/api/v1/organization-type/ | Unauthorized: /auth/api/v1/organization-type/
[2025-11-04 11:52:11,898] WARNING django.server | IP: - | Path: - | "GET /auth/api/v1/organization-type/?org_type_field=CO HTTP/1.1" 401 191
[2025-11-04 11:52:14,408] WARNING django.request | IP: 127.0.0.1 | Path: /auth/api/v1/organization-type/ | Unauthorized: /auth/api/v1/organization-type/
[2025-11-04 11:52:14,409] WARNING django.server | IP: - | Path: - | "GET /auth/api/v1/organization-type/?org_type_field=CO HTTP/1.1" 401 191
[2025-11-04 11:52:36,884] INFO django.server | IP: - | Path: - | "GET /auth/api/v1/organization-type/?org_type_field=CO HTTP/1.1" 200 577
[2025-11-04 11:53:45,008] INFO django.server | IP: - | Path: - | "GET /auth/api/v1/organization-type/ HTTP/1.1" 200 736
[2025-11-04 11:55:07,543] INFO django.server | IP: - | Path: - | "GET /auth/api/v1/organization-type/ HTTP/1.1" 200 736
[2025-11-04 11:55:11,219] INFO django.server | IP: - | Path: - | "GET /auth/api/v1/organization-type/ HTTP/1.1" 200 736
[2025-11-04 11:55:26,356] INFO django.server | IP: - | Path: - | "GET /auth/api/v1/organization-type/ HTTP/1.1" 200 736
[2025-11-04 11:57:33,191] INFO django.utils.autoreload | IP: - | Path: - | D:\Project\Rasaddam_Backend\apps\core\api.py changed, reloading.
[2025-11-04 11:57:37,132] INFO django.utils.autoreload | IP: - | Path: - | Watching for file changes with StatReloader
[2025-11-04 11:57:42,968] INFO django.server | IP: - | Path: - | "GET /auth/api/v1/organization-type/ HTTP/1.1" 200 736
[2025-11-04 11:57:45,929] INFO django.server | IP: - | Path: - | "GET /auth/api/v1/organization-type/ HTTP/1.1" 200 736
[2025-11-04 11:58:08,395] INFO django.utils.autoreload | IP: - | Path: - | D:\Project\Rasaddam_Backend\apps\core\api.py changed, reloading.
[2025-11-04 11:58:11,818] INFO django.utils.autoreload | IP: - | Path: - | Watching for file changes with StatReloader
[2025-11-04 11:58:15,499] INFO django.server | IP: - | Path: - | "GET /auth/api/v1/organization-type/ HTTP/1.1" 200 736
[2025-11-04 11:58:16,994] INFO django.server | IP: - | Path: - | "GET /auth/api/v1/organization-type/ HTTP/1.1" 200 736
[2025-11-04 11:58:36,417] INFO django.utils.autoreload | IP: - | Path: - | D:\Project\Rasaddam_Backend\apps\authentication\api\v1\api.py changed, reloading.
[2025-11-04 11:58:38,421] INFO django.utils.autoreload | IP: - | Path: - | Watching for file changes with StatReloader
[2025-11-04 11:58:43,169] INFO django.server | IP: - | Path: - | "GET /auth/api/v1/organization-type/ HTTP/1.1" 200 428