Router sets 'basename' on ViewSet

This commit is contained in:
Ryan P Kilby 2017-12-01 04:40:37 -05:00
parent 905a5579df
commit a80de2e108
2 changed files with 11 additions and 2 deletions

View File

@ -278,7 +278,12 @@ class SimpleRouter(BaseRouter):
if not prefix and regex[:2] == '^/': if not prefix and regex[:2] == '^/':
regex = '^' + regex[2:] regex = '^' + regex[2:]
view = viewset.as_view(mapping, **route.initkwargs) initkwargs = route.initkwargs.copy()
initkwargs.update({
'basename': basename,
})
view = viewset.as_view(mapping, **initkwargs)
name = route.name.format(basename=basename) name = route.name.format(basename=basename)
ret.append(url(regex, view, name=name)) ret.append(url(regex, view, name=name))

View File

@ -46,10 +46,14 @@ class ViewSetMixin(object):
instantiated view, we need to totally reimplement `.as_view`, instantiated view, we need to totally reimplement `.as_view`,
and slightly modify the view function that is created and returned. and slightly modify the view function that is created and returned.
""" """
# The suffix initkwarg is reserved for identifying the viewset type # The suffix initkwarg is reserved for displaying the viewset type.
# eg. 'List' or 'Instance'. # eg. 'List' or 'Instance'.
cls.suffix = None cls.suffix = None
# Setting a basename allows a view to reverse its action urls. This
# value is provided by the router through the initkwargs.
cls.basename = None
# actions must not be empty # actions must not be empty
if not actions: if not actions:
raise TypeError("The `actions` argument must be provided when " raise TypeError("The `actions` argument must be provided when "