mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-08-04 20:40:14 +03:00
Merge 98602900cf
into 4ce4a7c41a
This commit is contained in:
commit
812ba902f7
|
@ -274,21 +274,35 @@ class DefaultRouter(SimpleRouter):
|
|||
include_format_suffixes = True
|
||||
root_view_name = 'api-root'
|
||||
|
||||
def get_api_root_view(self):
|
||||
"""
|
||||
Return a view to use as the API root.
|
||||
"""
|
||||
def get_api_root_dict(self):
|
||||
api_root_dict = SortedDict()
|
||||
list_name = self.routes[0].name
|
||||
for prefix, viewset, basename in self.registry:
|
||||
api_root_dict[prefix] = list_name.format(basename=basename)
|
||||
return api_root_dict
|
||||
|
||||
def get_api_root_view(self):
|
||||
"""
|
||||
Return a view to use as the API root.
|
||||
"""
|
||||
enclosing = self
|
||||
|
||||
class APIRoot(views.APIView):
|
||||
_ignore_model_permissions = True
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(APIRoot, self).__init__(*args, **kwargs)
|
||||
self.api_root_dict = None
|
||||
|
||||
def get_api_root_dict(self):
|
||||
# We do this to avoid repeatedly calling enclosing.get_api_root_dict
|
||||
if self.api_root_dict is None:
|
||||
self.api_root_dict = enclosing.get_api_root_dict()
|
||||
return self.api_root_dict
|
||||
|
||||
def get(self, request, *args, **kwargs):
|
||||
ret = SortedDict()
|
||||
for key, url_name in api_root_dict.items():
|
||||
for key, url_name in self.get_api_root_dict().items():
|
||||
try:
|
||||
ret[key] = reverse(
|
||||
url_name,
|
||||
|
|
Loading…
Reference in New Issue
Block a user