def get_reverse_path(pk): """ :param pk: :return:list of dict in reverse order where keys are category name values are category id """ category_raw = get_category_raw_dict() path=[] def go_up(pk): path.append({category_raw[pk]['category_name']:pk}) try: return go_up(category_raw[pk]['parent_category']) except Exception: pass go_up(pk) return path[::-1]
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
def get_category_name(pk): return get_category_raw_dict()[pk]['category_name']
def get_category_list_dict(): return get_category_raw_dict()
def get_category_list_data_json(): return json.dumps(get_category_raw_dict())
def get_name_id_dict(): name_id_dict = {} for k,v in get_category_raw_dict(): name_id_dict[v['category_name']] = k return name_id_dict