|
23 | 23 | from rest_framework.utils import formatting
|
24 | 24 |
|
25 | 25 |
|
26 |
| -def get_view_name(view_cls, suffix=None): |
| 26 | +def get_view_name(view): |
27 | 27 | """
|
28 | 28 | Given a view class, return a textual name to represent the view.
|
29 | 29 | This name is used in the browsable API, and in OPTIONS responses.
|
30 | 30 |
|
31 | 31 | This function is the default for the `VIEW_NAME_FUNCTION` setting.
|
32 | 32 | """
|
33 |
| - name = view_cls.__name__ |
| 33 | + name = view.__class__.__name__ |
34 | 34 | name = formatting.remove_trailing_string(name, 'View')
|
35 | 35 | name = formatting.remove_trailing_string(name, 'ViewSet')
|
36 | 36 | 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) |
37 | 40 | if suffix:
|
38 | 41 | name += ' ' + suffix
|
39 | 42 |
|
40 | 43 | return name
|
41 | 44 |
|
42 | 45 |
|
43 |
| -def get_view_description(view_cls, html=False): |
| 46 | +def get_view_description(view, html=False): |
44 | 47 | """
|
45 | 48 | Given a view class, return a textual description to represent the view.
|
46 | 49 | This name is used in the browsable API, and in OPTIONS responses.
|
47 | 50 |
|
48 | 51 | This function is the default for the `VIEW_DESCRIPTION_FUNCTION` setting.
|
49 | 52 | """
|
50 |
| - description = view_cls.__doc__ or '' |
| 53 | + description = view.__class__.__doc__ or '' |
51 | 54 | description = formatting.dedent(smart_text(description))
|
52 | 55 | if html:
|
53 | 56 | return formatting.markup_description(description)
|
@@ -235,15 +238,15 @@ def get_view_name(self):
|
235 | 238 | browsable API.
|
236 | 239 | """
|
237 | 240 | func = self.settings.VIEW_NAME_FUNCTION
|
238 |
| - return func(self.__class__, getattr(self, 'suffix', None)) |
| 241 | + return func(self) |
239 | 242 |
|
240 | 243 | def get_view_description(self, html=False):
|
241 | 244 | """
|
242 | 245 | Return some descriptive text for the view, as used in OPTIONS responses
|
243 | 246 | and in the browsable API.
|
244 | 247 | """
|
245 | 248 | func = self.settings.VIEW_DESCRIPTION_FUNCTION
|
246 |
| - return func(self.__class__, html) |
| 249 | + return func(self, html) |
247 | 250 |
|
248 | 251 | # API policy instantiation methods
|
249 | 252 |
|
|
0 commit comments