Skip to content

Commit 57eae7b

Browse files
committed
Pass the the "title" attribute from each view when constructing Link instances.
This is part of a proposed solution to core-api/python-openapi-codec#28
1 parent 2a1fd3b commit 57eae7b

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

rest_framework/schemas.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,14 +454,29 @@ def get_link(self, path, method, view):
454454
if self.url and path.startswith('/'):
455455
path = path[1:]
456456

457+
title = self.get_title(view)
458+
457459
return coreapi.Link(
460+
title=title,
458461
url=urlparse.urljoin(self.url, path),
459462
action=method.lower(),
460463
encoding=encoding,
461464
fields=fields,
462465
description=description
463466
)
464467

468+
def get_title(self, view):
469+
"""
470+
Determine a title from a view instance.
471+
472+
If the 'title' attribute is not set on the view, then an empty title is returned.
473+
"""
474+
title = ""
475+
if hasattr(view, "title"):
476+
title = view.title
477+
478+
return title
479+
465480
def get_description(self, path, method, view):
466481
"""
467482
Determine a link description.

0 commit comments

Comments
 (0)