Changeset View
Changeset View
Standalone View
Standalone View
swh/web/api/views/utils.py
Show All 37 Lines | def api_lookup(lookup_fn, *args, | ||||
Raises: | Raises: | ||||
NotFoundExp or whatever `lookup_fn` raises. | NotFoundExp or whatever `lookup_fn` raises. | ||||
""" # noqa | """ # noqa | ||||
if enrich_fn is None: | if enrich_fn is None: | ||||
enrich_fn = (lambda x: x) | enrich_fn = (lambda x: x) | ||||
res = lookup_fn(*args) | res = lookup_fn(*args) | ||||
if not res: | if res is None: | ||||
raise NotFoundExc(notfound_msg) | raise NotFoundExc(notfound_msg) | ||||
if isinstance(res, (map, list, GeneratorType)): | if isinstance(res, (map, list, GeneratorType)): | ||||
return [enrich_fn(x) for x in res] | return [enrich_fn(x) for x in res] | ||||
return enrich_fn(res) | return enrich_fn(res) | ||||
@api_view(['GET', 'HEAD']) | @api_view(['GET', 'HEAD']) | ||||
def api_home(request): | def api_home(request): | ||||
Show All 19 Lines |