Skip to content

Commit

Permalink
fix(api): custom dashboard for enum type
Browse files Browse the repository at this point in the history
  • Loading branch information
pycook committed Aug 26, 2024
1 parent 834054e commit eafb5f0
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion cmdb-api/api/lib/cmdb/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,10 +379,17 @@ def attribute_counter(cls, custom):
other_filter = "{}".format(other_filter) if other_filter else ''

if custom['options'].get('ret') == 'cis':
enum_map = {}
for _attr_id in attr_ids:
_attr = AttributeCache.get(_attr_id)
if _attr:
enum_map[_attr.alias] = AttributeManager.get_enum_map(_attr_id)

query = "_type:({}),{}".format(";".join(map(str, type_ids)), other_filter)
s = search(query, fl=attr_ids, ret_key='alias', count=100)
try:
cis, _, _, _, _, _ = s.search()
cis = [{k: (enum_map.get(k) or {}).get(v, v) for k, v in ci.items()} for ci in cis]
except SearchError as e:
current_app.logger.error(e)
return
Expand Down Expand Up @@ -431,7 +438,7 @@ def attribute_counter(cls, custom):
# level = 3
enum_map3 = AttributeManager.get_enum_map(attr_ids[2])
for v1 in origin_result:
if not isinstance(result[v1], dict):
if not isinstance(result[enum_map1.get(v1, v1)], dict):
continue
for v2 in origin_result[v1]:
query = "_type:({}),{},{}:{},{}:{}".format(";".join(map(str, type_ids)), other_filter,
Expand Down

0 comments on commit eafb5f0

Please sign in to comment.