在IP/identity/users的页面中,想要显示每个user属于的tenant,并给出这个tenant中的各个role。
这里主要是要注意调用api时,尽量少的进行for循环,此处给出两种情况,在现实情况中,由于进行http的访问不同,所以页面加载速度差距很大:
for tenants_one in tenants:
user_roles = api.keystone.get_project_users_roles(self.request,tenants_one.id)
dict_user_roles[tenants_one.id] = user_roles
user_roles = []
# import pdb
# pdb.set_trace()
for user_one in userslist:
for tenants_one in tenants:
if user_one['id'] in dict_user_roles[tenants_one.id].keys():
role_id = dict_user_roles[tenants_one.id][user_one['id']]
for roleid_element in role_id:
for role_element in roles:
if roleid_element == role_element.id:
r_name.append(role_element.name)
if r_name !=[]:
str_project_role = str_project_role + tenants_one.name + ':'
for x in r_name:
str_project_role = str_project_role + x + ','+''
str_project_role = str_project_role + ''
r_name = []
user_one['prorole'] = str_project_role
str_project_role = ''
# user_s1 = users
# for user_one in userslist:
# for tenants_one in tenants:
# # str_project_role = ''
# # str_project_role = str_project_role+tenants_one.name + ':'
# user_roles = api.keystone.get_project_users_roles(self.request,tenants_one.id)
# if user_one['id'] in user_roles.keys():
# role_id = user_roles[user_one['id']]
# for roleid_element in role_id:
# for role_element in roles:
# if roleid_element == role_element.id:
# r_name.append(role_element.name)
# # r_name.append(roles[roleid_element])
# if r_name != []:
# dict1[tenants_one.name] = r_name
# LL.append(dict1)
# # for x in r_name:
# # str_project_role = ' ' + str_project_role + x
# # str_projcet_role =
# str_project_role = str_project_role + tenants_one.name + ':'
# for x in r_name:
# str_project_role = str_project_role + x + ','
# str_project_role = str_project_role + ' ;'
# r_name = []
# dict1 ={}
# # user_one[user_role] = LL
# user_one['prorole'] = str_project_role
# str_project_role = ''
# LLL.append(LL)
# LL = []
其中注释掉的代码,非常糟糕,仅供参考理解
阅读(1431) | 评论(0) | 转发(0) |