Merge pull request #3440 from jumpserver/dev_au

[Update] 资产用户列表支持模糊搜索
pull/3445/head
BaiJiangJie 2019-11-15 15:03:27 +08:00 committed by GitHub
commit 61a8d6a5ca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 5 deletions

View File

@ -38,6 +38,9 @@ class AssetUserQuerySet(list):
if len(v) == 0: if len(v) == 0:
return self return self
if k.find("__in") >= 0: if k.find("__in") >= 0:
_k = k.split('__')[0]
in_kwargs[_k] = v
else:
in_kwargs[k] = v in_kwargs[k] = v
for k in in_kwargs: for k in in_kwargs:
kwargs.pop(k) kwargs.pop(k)
@ -45,17 +48,16 @@ class AssetUserQuerySet(list):
if len(in_kwargs) == 0: if len(in_kwargs) == 0:
return self return self
for i in self: for i in self:
matched = True matched = False
for k, v in in_kwargs.items(): for k, v in in_kwargs.items():
key = k.split('__')[0] attr = getattr(i, k, None)
attr = getattr(i, key, None)
# 如果属性或者value中是uuid,则转换成string # 如果属性或者value中是uuid,则转换成string
if isinstance(v[0], uuid.UUID): if isinstance(v[0], uuid.UUID):
v = [str(i) for i in v] v = [str(i) for i in v]
if isinstance(attr, uuid.UUID): if isinstance(attr, uuid.UUID):
attr = str(attr) attr = str(attr)
if attr not in v: if v in attr:
matched = False matched = True
if matched: if matched:
queryset.append(i) queryset.append(i)
return AssetUserQuerySet(queryset) return AssetUserQuerySet(queryset)