forked from sabkaryan/python-core-homework
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path__init__.py
More file actions
27 lines (19 loc) · 763 Bytes
/
__init__.py
File metadata and controls
27 lines (19 loc) · 763 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
from ex1.mapping import RAW_MAPPING
def build_roles_tree(mapping):
"""
:param mapping: маппинг ролей в категории
:return: дерево ролей
"""
categories = mapping.get('categories')
roles = mapping.get('roles')
for role in roles.values():
role['text'] = role.pop('name')
sorted_list = mapping.get('categoryIdsSorted')
full_categories = {'categories': []}
for category_id in sorted_list:
full_categories['categories'].append(categories.get(category_id))
for cat in full_categories['categories']:
cat['id'] = f'category-{cat["id"]}'
cat['text'] = cat.pop('name')
cat['items'] = [roles[i] for i in cat.pop('roleIds')]
return full_categories