Skip to content

Commit

Permalink
resolve: change code style
Browse files Browse the repository at this point in the history
  • Loading branch information
rolin999 committed Nov 18, 2024
1 parent c615aa4 commit 0c30cdf
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/bk-user/bkuser/apis/web/audit/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,20 @@

class AuditRecordListInputSLZ(serializers.Serializer):
creator = serializers.CharField(help_text="操作人", required=False, allow_blank=True)
created_at = serializers.DateTimeField(help_text="操作时间", required=False)
operation = serializers.ChoiceField(help_text="操作行为", choices=OperationEnum.get_choices(), required=False)
object_type = serializers.ChoiceField(
help_text="操作对象类型", choices=ObjectTypeEnum.get_choices(), required=False
)
object_name = serializers.CharField(help_text="操作对象名称", required=False, allow_blank=True)
created_at = serializers.DateTimeField(help_text="操作时间", required=False)


class AuditRecordListOutputSLZ(serializers.Serializer):
creator = serializers.SerializerMethodField(help_text="操作人")
created_at = serializers.DateTimeField(help_text="操作时间")
operation = serializers.CharField(help_text="操作行为")
object_type = serializers.CharField(help_text="操作对象类型")
object_name = serializers.CharField(help_text="操作对象名称", allow_blank=True, allow_null=True)
created_at = serializers.DateTimeField(help_text="操作时间")

def get_creator(self, obj: OperationAuditRecord) -> str:
return self.context["user_display_name_map"].get(obj.creator) or obj.creator
2 changes: 1 addition & 1 deletion src/bk-user/bkuser/apis/web/audit/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@

urlpatterns = [
# 操作审计列表
path("", views.AuditRecordListAPIView.as_view(), name="audit.list", ),
path("", views.AuditRecordListAPIView.as_view(), name="audit.list"),
]
3 changes: 1 addition & 2 deletions src/bk-user/bkuser/apis/web/audit/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,7 @@ def get_queryset(self):
return OperationAuditRecord.objects.filter(**filters)

def get_serializer_context(self) -> Dict[str, Any]:
queryset = self.paginate_queryset(self.get_queryset())
tenant_user_ids = [record.creator for record in queryset]
tenant_user_ids = self.paginate_queryset(self.get_queryset().values_list("creator", flat=True))
return {
"user_display_name_map": TenantUserHandler.get_tenant_user_display_name_map_by_ids(tenant_user_ids),
}
Expand Down

0 comments on commit 0c30cdf

Please sign in to comment.