import --> first steps of tag distribution

This commit is contained in:
2026-01-19 14:04:41 +03:30
parent 057943b37f
commit 54047e625b
4 changed files with 30 additions and 0 deletions

View File

@@ -11,6 +11,7 @@ VISIBILITY_MAP = {
'rancher': 'organization', 'rancher': 'organization',
'rancherorganizationlink': 'organization', # noqa 'rancherorganizationlink': 'organization', # noqa
'tagbatch': 'organization', # noqa 'tagbatch': 'organization', # noqa
'tagdistribution': ['assigner_org', 'assigned_org']
# 'deviceactivationcode': 'organization', # 'deviceactivationcode': 'organization',
# 'deviceversion': 'organization', # 'deviceversion': 'organization',

View File

@@ -0,0 +1,6 @@
class TagDistributionService:
"""
service of distribute tags in organizations
"""
pass

View File

@@ -347,3 +347,25 @@ class TagBatchViewSet(BaseViewSet, SoftDeleteMixin, DynamicSearchMixin, viewsets
class TagDistributionViewSet(BaseViewSet, SoftDeleteMixin, DynamicSearchMixin, viewsets.ModelViewSet): class TagDistributionViewSet(BaseViewSet, SoftDeleteMixin, DynamicSearchMixin, viewsets.ModelViewSet):
queryset = tag_models.TagDistribution.objects.all() queryset = tag_models.TagDistribution.objects.all()
serializer_class = TagDistributionSerializer 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)

View File

@@ -162,6 +162,7 @@ class TagDistributionSerializer(serializers.ModelSerializer):
representation = super().to_representation(instance) representation = super().to_representation(instance)
representation['batch'] = { representation['batch'] = {
'id': instance.batch.id,
'batch_creator': instance.batch.organization.name, 'batch_creator': instance.batch.organization.name,
'batch_identity': instance.batch.batch_identity 'batch_identity': instance.batch.batch_identity
} }