From 54047e625baa1c771ab875580ce4ed9a834923cc Mon Sep 17 00:00:00 2001 From: Mojtaba-z Date: Mon, 19 Jan 2026 14:04:41 +0330 Subject: [PATCH] import --> first steps of tag distribution --- apps/core/visibility_registry.py | 1 + .../tag/services/tag_distribution_services.py | 6 +++++ apps/tag/web/api/v1/api.py | 22 +++++++++++++++++++ apps/tag/web/api/v1/serializers.py | 1 + 4 files changed, 30 insertions(+) create mode 100644 apps/tag/services/tag_distribution_services.py diff --git a/apps/core/visibility_registry.py b/apps/core/visibility_registry.py index 8b3e9bd..06596e7 100644 --- a/apps/core/visibility_registry.py +++ b/apps/core/visibility_registry.py @@ -11,6 +11,7 @@ VISIBILITY_MAP = { 'rancher': 'organization', 'rancherorganizationlink': 'organization', # noqa 'tagbatch': 'organization', # noqa + 'tagdistribution': ['assigner_org', 'assigned_org'] # 'deviceactivationcode': 'organization', # 'deviceversion': 'organization', diff --git a/apps/tag/services/tag_distribution_services.py b/apps/tag/services/tag_distribution_services.py new file mode 100644 index 0000000..6eaf2b0 --- /dev/null +++ b/apps/tag/services/tag_distribution_services.py @@ -0,0 +1,6 @@ +class TagDistributionService: + """ + service of distribute tags in organizations + """ + + pass diff --git a/apps/tag/web/api/v1/api.py b/apps/tag/web/api/v1/api.py index 5465352..29d6fc4 100644 --- a/apps/tag/web/api/v1/api.py +++ b/apps/tag/web/api/v1/api.py @@ -347,3 +347,25 @@ class TagBatchViewSet(BaseViewSet, SoftDeleteMixin, DynamicSearchMixin, viewsets class TagDistributionViewSet(BaseViewSet, SoftDeleteMixin, DynamicSearchMixin, viewsets.ModelViewSet): queryset = tag_models.TagDistribution.objects.all() serializer_class = TagDistributionSerializer + filter_backends = [SearchFilter] + search_fields = [ + 'batch__batch_identity', + 'tag__tag_code', + 'assigner_org__name', + 'assigned_org__name', + 'species_code', + ] + + def list(self, request, *args, **kwargs): + """ + list of tag distributions + """ + queryset = self.get_queryset(visibility_by_org_scope=True).order_by('-create_date') + + queryset = self.filter_queryset(self.filter_query(queryset)) + + page = self.paginate_queryset(queryset) + if page is not None: # noqa + serializer = self.get_serializer(page, many=True) + return self.get_paginated_response(serializer.data) + return Response(self.serializer_class(queryset).data) diff --git a/apps/tag/web/api/v1/serializers.py b/apps/tag/web/api/v1/serializers.py index d75cecc..f6d72de 100644 --- a/apps/tag/web/api/v1/serializers.py +++ b/apps/tag/web/api/v1/serializers.py @@ -162,6 +162,7 @@ class TagDistributionSerializer(serializers.ModelSerializer): representation = super().to_representation(instance) representation['batch'] = { + 'id': instance.batch.id, 'batch_creator': instance.batch.organization.name, 'batch_identity': instance.batch.batch_identity }