Skip to content

Commit

Permalink
Update get_view_description to conform to changes in DRF's version
Browse files Browse the repository at this point in the history
  • Loading branch information
jbradberry committed Jun 10, 2019
1 parent b132f1c commit 796ed94
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 25 deletions.
31 changes: 7 additions & 24 deletions awx/api/generics.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,21 +119,12 @@ def dispatch(self, request, *args, **kwargs):
return ret


def get_view_description(cls, request, html=False):
'''
Wrapper around REST framework get_view_description() to support
get_description() method and view_description property on a view class.
def get_view_description(view, html=False):
'''Wrapper around REST framework get_view_description() to continue
to support our historical div.
'''
if hasattr(cls, 'get_description') and callable(cls.get_description):
desc = cls().get_description(request, html=html)
cls = type(cls.__name__, (object,), {'__doc__': desc})
elif hasattr(cls, 'view_description'):
if callable(cls.view_description):
view_desc = cls.view_description()
else:
view_desc = cls.view_description
cls = type(cls.__name__, (object,), {'__doc__': view_desc})
desc = views.get_view_description(cls, html=html)
desc = views.get_view_description(view, html=html)
if html:
desc = '<div class="description">%s</div>' % desc
return mark_safe(desc)
Expand Down Expand Up @@ -246,14 +237,6 @@ def get_authenticate_header(self, request):
# `curl https://user:pass@tower.example.org/api/v2/job_templates/N/launch/`
return 'Bearer realm=api authorization_url=/api/o/authorize/'

def get_view_description(self, html=False):
"""
Return some descriptive text for the view, as used in OPTIONS responses
and in the browsable API.
"""
func = self.settings.VIEW_DESCRIPTION_FUNCTION
return func(self.__class__, getattr(self, '_request', None), html)

def get_description_context(self):
return {
'view': self,
Expand All @@ -262,8 +245,8 @@ def get_description_context(self):
'swagger_method': getattr(self.request, 'swagger_method', None),
}

def get_description(self, request, html=False):
self.request = request
@property
def description(self):
template_list = []
for klass in inspect.getmro(type(self)):
template_basename = camelcase_to_underscore(klass.__name__)
Expand Down
1 change: 0 additions & 1 deletion awx/api/swagger.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ def get_link(self, path, method, base_url):
return link

def get_description(self, path, method):
self.view._request = self.view.request
setattr(self.view.request, 'swagger_method', method)
description = super(AutoSchema, self).get_description(path, method)
return description
Expand Down

0 comments on commit 796ed94

Please sign in to comment.