Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender-addons.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'blenderkit/categories.py')
-rw-r--r--blenderkit/categories.py25
1 files changed, 24 insertions, 1 deletions
diff --git a/blenderkit/categories.py b/blenderkit/categories.py
index f91fe512..46d10f86 100644
--- a/blenderkit/categories.py
+++ b/blenderkit/categories.py
@@ -81,11 +81,34 @@ def get_category_path(categories, category):
slug = ch['slug']
while parents.get(slug):
slug = parents.get(slug)
-
category_path.insert(0, slug)
return category_path
check_categories.append(ch)
+def get_category_name_path(categories, category):
+ '''finds the category in all possible subcategories and returns the path to it'''
+ category_path = []
+ check_categories = categories[:]
+ parents = {}
+ utils.pprint(categories)
+ while len(check_categories) > 0:
+ ccheck = check_categories.pop()
+ # print(ccheck['name'])
+ if not ccheck.get('children'):
+ continue
+
+ for ch in ccheck['children']:
+ # print(ch['name'])
+ parents[ch['slug']] = ccheck['slug']
+
+ if ch['slug'] == category:
+ category_path = [ch['slug']]
+ slug = ch['slug']
+ while parents.get(slug):
+ slug = parents.get(slug)
+ category_path.insert(0, slug)
+ return category_path
+ check_categories.append(ch)
def get_category(categories, cat_path=()):
for category in cat_path: