mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-07-27 16:40:03 +03:00
Remove unnecessary if-statement
This commit is contained in:
parent
0baeb6046f
commit
64dcb23852
|
@ -152,11 +152,12 @@ class SimpleRouter(BaseRouter):
|
||||||
"""
|
"""
|
||||||
# use `issubclass` and not `isinstance` because `viewset` may be an
|
# use `issubclass` and not `isinstance` because `viewset` may be an
|
||||||
# uninstantiated class.
|
# uninstantiated class.
|
||||||
is_viewset = issubclass(viewset, ViewSetMixin) if isclass(viewset) else False
|
is_cls = isclass(viewset)
|
||||||
|
is_viewset = is_cls and issubclass(viewset, ViewSetMixin)
|
||||||
if not is_viewset:
|
if not is_viewset:
|
||||||
# `viewset` is not a REST Framework ViewSet,
|
# `viewset` is not a REST Framework ViewSet,
|
||||||
# so we can't dynamically generate any routes
|
# so we can't dynamically generate any routes
|
||||||
is_cbv = issubclass(viewset, View) if isclass(viewset) else False
|
is_cbv = is_cls and issubclass(viewset, View)
|
||||||
if is_cbv:
|
if is_cbv:
|
||||||
return [viewset.as_view(), ]
|
return [viewset.as_view(), ]
|
||||||
return [viewset, ]
|
return [viewset, ]
|
||||||
|
@ -256,16 +257,15 @@ class SimpleRouter(BaseRouter):
|
||||||
# `viewset` is a Django CBV. REST Frameworks `ViewSet`s
|
# `viewset` is a Django CBV. REST Frameworks `ViewSet`s
|
||||||
# are included in this if-statement because `ViewSet`s
|
# are included in this if-statement because `ViewSet`s
|
||||||
# subclass `APIView`, which subclasses `View`.
|
# subclass `APIView`, which subclasses `View`.
|
||||||
view = viewset.as_view(mapping, **initkwargs)
|
|
||||||
else:
|
|
||||||
# assume that `viewset` is a Django view function
|
|
||||||
view = viewset
|
|
||||||
|
|
||||||
if isinstance(route, Route):
|
|
||||||
# Only actions which actually exist on the viewset will be bound
|
# Only actions which actually exist on the viewset will be bound
|
||||||
mapping = self.get_method_map(viewset, route.mapping)
|
mapping = self.get_method_map(viewset, route.mapping)
|
||||||
if not mapping:
|
if not mapping:
|
||||||
continue
|
continue
|
||||||
|
view = viewset.as_view(mapping, **initkwargs)
|
||||||
|
else:
|
||||||
|
# assume that `viewset` is a Django view
|
||||||
|
view = viewset
|
||||||
|
|
||||||
# Build the url pattern
|
# Build the url pattern
|
||||||
regex = route.url.format(
|
regex = route.url.format(
|
||||||
|
@ -289,8 +289,6 @@ class SimpleRouter(BaseRouter):
|
||||||
|
|
||||||
name = route.name.format(basename=basename)
|
name = route.name.format(basename=basename)
|
||||||
django_path = re_path(regex, view, name=name)
|
django_path = re_path(regex, view, name=name)
|
||||||
else:
|
|
||||||
django_path = path(prefix, view, name=prefix)
|
|
||||||
|
|
||||||
ret.append(django_path)
|
ret.append(django_path)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user