Skip to content

Commit

Permalink
fix: 修复 admin42 应用列表带查询参数时查询结果不正确 (#469)
Browse files Browse the repository at this point in the history
  • Loading branch information
jiayuan929 authored May 27, 2023
1 parent feba1e5 commit d8a5c36
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions apiserver/paasng/paasng/plat_admin/admin42/views/applications.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,16 +78,22 @@ def get_app_resource_context_data(self, app_resource_quotas, **kwargs):
# 手动按资源的使用量排序分页
offset = self.paginator.get_offset(self.request)
limit = self.paginator.get_limit(self.request)
queryset = self.filter_queryset(self.get_queryset())

if self.request.query_params.get('search_term'):
# 有查询参数则不按资源用量排序
page = queryset[offset : offset + limit]
else:
# 应用资源排序后的信息
page_app_code_list = list(app_resource_quotas.keys())[offset : offset + limit]
page = queryset.filter(code__in=page_app_code_list)

# 应用资源排序后的信息
page_app_code_list = list(app_resource_quotas.keys())[offset : offset + limit]
page = self.filter_queryset(self.get_queryset()).filter(code__in=page_app_code_list)
data = self.get_serializer(page, many=True, context={"app_resource_quotas": app_resource_quotas}).data
data = sorted(data, key=lambda item: item['resource_quotas']['memory'], reverse=True)
kwargs['application_list'] = data

# 没有调用默认的 paginate_queryset 方法,需要手动给 paginator 的参数赋值
self.paginator.count = self.paginator.get_count(self.get_queryset())
self.paginator.count = self.paginator.get_count(queryset)
self.paginator.limit = limit
self.paginator.offset = offset
self.paginator.request = self.request
Expand Down

0 comments on commit d8a5c36

Please sign in to comment.