mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-26 03:23:59 +03:00
Fix guardian import (#4612)
This commit is contained in:
parent
0fe0e1e703
commit
30bf9df5d0
|
@ -207,7 +207,6 @@ guardian = None
|
||||||
try:
|
try:
|
||||||
if 'guardian' in settings.INSTALLED_APPS:
|
if 'guardian' in settings.INSTALLED_APPS:
|
||||||
import guardian
|
import guardian
|
||||||
import guardian.shortcuts # Fixes #1624
|
|
||||||
except ImportError:
|
except ImportError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
|
@ -289,6 +289,11 @@ class DjangoObjectPermissionsFilter(BaseFilterBackend):
|
||||||
perm_format = '%(app_label)s.view_%(model_name)s'
|
perm_format = '%(app_label)s.view_%(model_name)s'
|
||||||
|
|
||||||
def filter_queryset(self, request, queryset, view):
|
def filter_queryset(self, request, queryset, view):
|
||||||
|
# We want to defer this import until run-time, rather than import-time.
|
||||||
|
# See https://github.com/tomchristie/django-rest-framework/issues/4608
|
||||||
|
# (Also see #1624 for why we need to make this import explicitly)
|
||||||
|
from guardian.shortcuts import get_objects_for_user
|
||||||
|
|
||||||
extra = {}
|
extra = {}
|
||||||
user = request.user
|
user = request.user
|
||||||
model_cls = queryset.model
|
model_cls = queryset.model
|
||||||
|
@ -302,4 +307,4 @@ class DjangoObjectPermissionsFilter(BaseFilterBackend):
|
||||||
extra = {'accept_global_perms': False}
|
extra = {'accept_global_perms': False}
|
||||||
else:
|
else:
|
||||||
extra = {}
|
extra = {}
|
||||||
return guardian.shortcuts.get_objects_for_user(user, permission, queryset, **extra)
|
return get_objects_for_user(user, permission, queryset, **extra)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user