perf: histories account

pull/9008/head
feng 2022-11-01 11:13:18 +08:00
parent 41ee6a64bd
commit 796758cbb2
1 changed files with 7 additions and 7 deletions

View File

@ -1,6 +1,6 @@
from rest_framework.decorators import action from rest_framework.decorators import action
from rest_framework.response import Response from rest_framework.response import Response
from rest_framework.generics import CreateAPIView from rest_framework.generics import CreateAPIView, get_object_or_404
from orgs.mixins.api import OrgBulkModelViewSet from orgs.mixins.api import OrgBulkModelViewSet
from rbac.permissions import RBACPermission from rbac.permissions import RBACPermission
@ -41,7 +41,8 @@ class AccountSecretsViewSet(RecordViewLogMixin, AccountViewSet):
因为可能要导出所有账号所以单独建立了一个 viewset 因为可能要导出所有账号所以单独建立了一个 viewset
""" """
serializer_classes = { serializer_classes = {
'default': serializers.AccountSecretSerializer 'default': serializers.AccountSecretSerializer,
'histories': serializers.AccountHistorySerializer,
} }
http_method_names = ['get', 'options'] http_method_names = ['get', 'options']
# Todo: 记得打开 # Todo: 记得打开
@ -52,12 +53,11 @@ class AccountSecretsViewSet(RecordViewLogMixin, AccountViewSet):
'histories': ['assets.view_accountsecret'], 'histories': ['assets.view_accountsecret'],
} }
@action(methods=['get'], detail=True, url_path='histories', serializer_class=serializers.AccountHistorySerializer) @action(methods=['get'], detail=True, url_path='histories')
def histories(self, request, *args, **kwargs): def histories(self, request, *args, **kwargs):
account = self.get_object() account = get_object_or_404(self.get_queryset(), **kwargs)
histories = account.history.all() self.queryset = account.history.all()
serializer = serializers.AccountHistorySerializer(histories, many=True) return super().list(request, *args, **kwargs)
return Response(serializer.data)
class AccountTaskCreateAPI(CreateAPIView): class AccountTaskCreateAPI(CreateAPIView):