Commit 670e5b7b authored by Mark Steadman's avatar Mark Steadman

`Allows resource_kwargs` to be specified in the REST shortcut function

parent b0a544d5
......@@ -56,6 +56,10 @@ def rest(resource, **kwargs):
(optional) Override the default authorisers for this endpoint.
(Defaults to the value of ``settings.API_DEFAULT_AUTHORISERS``.)
:type authorisers: list, tuple
:param resource_kwargs
[optional] Add to the default keyword argument dict that is passed
to the resource.
"""
from api.resources import registry, ModelResource
......@@ -83,6 +87,7 @@ def rest(resource, **kwargs):
relations = kwargs.pop('relations', ())
authorisers = kwargs.pop('authorisers', None)
authenticators = kwargs.pop('authenticators', None)
resource_kwargs_getter = kwargs.pop('resource_kwargs', None)
if isinstance(resource, ModelBase):
opts = resource._meta
......@@ -149,6 +154,9 @@ def rest(resource, **kwargs):
if authorisers is not None:
kw['authorisers'] = authorisers
if resource_kwargs_getter is not None:
kw['resource_kwargs_getter'] = resource_kwargs_getter
mixin = modelmixin_factory(list_resource.model, **kw)
list_view = type(
......
......@@ -636,7 +636,7 @@ class RelationshipView(ModelViewBase):
def modelmixin_factory(
Model, prepopulated_fields={}, queryset=None,
authenticators=None, authorisers=None
authenticators=None, authorisers=None, resource_kwargs_getter=None
):
"""
A factory function for creating a model view mixin in realtime.
......@@ -682,6 +682,11 @@ def modelmixin_factory(
if queryset is not None:
kwargs['queryset'] = queryset(self.request)
if callable(resource_kwargs_getter):
kwargs.update(
resource_kwargs_getter(self.request)
)
return kwargs
def form_valid(self, form):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment