def get_next_sub_category(path): """ path should be like "1 > 2 > 3". ie space to left and right of > symbol. :param path: :return: returns dict. Key name 'categories' has dict with key as category id and values is a boolean which refers to the condition whether it is the last level or not. """ categories = {} path = sanitize(path) category_data = get_category_hierarchy() #since we are navigating into the category by pop() method. go_into_path(category_data, path) for k, v in category_data.items(): categories[k] = 'False' if bool(v) else 'True' return {'categories': categories}
def get_end_categories(path): """ path should be like "1 > 2 > 3". ie space to left and right of > symbol. :param path: :return: returns dict with key names as category names and id as their value """ category_raw = get_category_raw_dict() categories = {} path = sanitize(path) category_data = get_category_hierarchy() go_into_path(category_data, path) def go_below(category_data): for k, v in category_data.items(): if bool(v): go_below(category_data[k]) else: categories[category_raw[k]['category_name']] = k go_below(category_data) return categories