Exemplo n.º 1
0
def parenting_cat(cat, depth=1):
    """Return the name of category id `cat` (or name), stopping at level
    `depth`."""
    if not cat:
        return None
    _, path = fsc.search_categories(cat)
    cat_is_name = fsc.choose_type(cat)
    answer = path[depth] if len(path) > depth else path[-1]
    if cat_is_name:
        return answer
    return fsc.CAT_TO_ID[:answer]
Exemplo n.º 2
0
 def parenting_cat(place, depth):
     """Return the category of `place`, without going beyond `depth`"""
     _, path = fsc.search_categories(place['_id'])
     if len(path) > depth:
         return fsc.CAT_TO_ID[:path[depth]]
     return fsc.CAT_TO_ID[:path[-1]]