Skip to content

Commit

Permalink
using queryset from viewset if defined
Browse files Browse the repository at this point in the history
  • Loading branch information
Mirek Simek committed Nov 22, 2017
1 parent 4ece8a8 commit 8dbbd7d
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions rest_delegated_permissions/permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ def decorate(viewset_class):
self.set_model_permissions(model_class, permissions,
force_add_django_permissions=add_django_permissions)

model_queryset_factory = self.create_queryset_factory(model_class)
model_queryset_factory = self.create_queryset_factory(model_class, getattr(viewset_class, 'queryset', None))

return type('%s_perms' % viewset_class.__name__, (viewset_class, ), {
'permission_classes': (self.get_model_permissions(model_class),),
Expand All @@ -305,14 +305,17 @@ def has_permission(self, request, view):

return _Permission

def create_queryset_factory(self, model_class):
def create_queryset_factory(self, model_class, base_queryset=None):
"""
returns lambda (user, action) => queryset(model_class)
"""

def model_filter(user, action):
querysets = []
qs = self.get_base_queryset(model_class)
if base_queryset is not None:
qs = base_queryset
else:
qs = self.get_base_queryset(model_class)

for partial_qs in self.filtered_model_queryset(model_class, qs, user, action):
querysets.append(partial_qs)
Expand Down

0 comments on commit 8dbbd7d

Please sign in to comment.