Skip to content

Commit 4890208

Browse files
author
Ryan P Kilby
committed
Pass view inst instead of class to get_view_name()
1 parent 09916f4 commit 4890208

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

rest_framework/views.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,31 +23,34 @@
2323
from rest_framework.utils import formatting
2424

2525

26-
def get_view_name(view_cls, suffix=None):
26+
def get_view_name(view):
2727
"""
2828
Given a view class, return a textual name to represent the view.
2929
This name is used in the browsable API, and in OPTIONS responses.
3030
3131
This function is the default for the `VIEW_NAME_FUNCTION` setting.
3232
"""
33-
name = view_cls.__name__
33+
name = view.__class__.__name__
3434
name = formatting.remove_trailing_string(name, 'View')
3535
name = formatting.remove_trailing_string(name, 'ViewSet')
3636
name = formatting.camelcase_to_spaces(name)
37+
38+
# Suffix may be set by some Views, such as a ViewSet.
39+
suffix = getattr(view, 'suffix', None)
3740
if suffix:
3841
name += ' ' + suffix
3942

4043
return name
4144

4245

43-
def get_view_description(view_cls, html=False):
46+
def get_view_description(view, html=False):
4447
"""
4548
Given a view class, return a textual description to represent the view.
4649
This name is used in the browsable API, and in OPTIONS responses.
4750
4851
This function is the default for the `VIEW_DESCRIPTION_FUNCTION` setting.
4952
"""
50-
description = view_cls.__doc__ or ''
53+
description = view.__class__.__doc__ or ''
5154
description = formatting.dedent(smart_text(description))
5255
if html:
5356
return formatting.markup_description(description)
@@ -235,15 +238,15 @@ def get_view_name(self):
235238
browsable API.
236239
"""
237240
func = self.settings.VIEW_NAME_FUNCTION
238-
return func(self.__class__, getattr(self, 'suffix', None))
241+
return func(self)
239242

240243
def get_view_description(self, html=False):
241244
"""
242245
Return some descriptive text for the view, as used in OPTIONS responses
243246
and in the browsable API.
244247
"""
245248
func = self.settings.VIEW_DESCRIPTION_FUNCTION
246-
return func(self.__class__, html)
249+
return func(self, html)
247250

248251
# API policy instantiation methods
249252

0 commit comments

Comments
 (0)