mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-08-02 19:40:13 +03:00
Merge 0fc0ee1778
into 499533d219
This commit is contained in:
commit
dde8b51322
|
@ -21,6 +21,8 @@ matrix:
|
||||||
- { python: "3.6", env: DJANGO=master }
|
- { python: "3.6", env: DJANGO=master }
|
||||||
- { python: "3.6", env: DJANGO=1.11 }
|
- { python: "3.6", env: DJANGO=1.11 }
|
||||||
- { python: "3.6", env: DJANGO=2.0 }
|
- { python: "3.6", env: DJANGO=2.0 }
|
||||||
|
- { python: "3.6", env: DJANGO=2.0 }
|
||||||
|
- { python: "3.6", env: TOXENV=py36-django20-optionals }
|
||||||
- { python: "3.6", env: DJANGO=2.1 }
|
- { python: "3.6", env: DJANGO=2.1 }
|
||||||
- { python: "3.6", env: TOXENV=base }
|
- { python: "3.6", env: TOXENV=base }
|
||||||
- { python: "2.7", env: TOXENV=lint }
|
- { python: "2.7", env: TOXENV=lint }
|
||||||
|
@ -33,6 +35,13 @@ matrix:
|
||||||
- tox --installpkg ./dist/djangorestframework-*.whl
|
- tox --installpkg ./dist/djangorestframework-*.whl
|
||||||
- tox # test sdist
|
- tox # test sdist
|
||||||
|
|
||||||
|
- python: "3.6"
|
||||||
|
env: TOXENV=dist-optionals
|
||||||
|
script:
|
||||||
|
- python setup.py bdist_wheel
|
||||||
|
- tox --installpkg ./dist/djangorestframework-*.whl
|
||||||
|
- tox # test sdist
|
||||||
|
|
||||||
exclude:
|
exclude:
|
||||||
- { python: "2.7", env: DJANGO=master }
|
- { python: "2.7", env: DJANGO=master }
|
||||||
- { python: "2.7", env: DJANGO=2.0 }
|
- { python: "2.7", env: DJANGO=2.0 }
|
||||||
|
|
|
@ -139,16 +139,6 @@ except ImportError:
|
||||||
requests = None
|
requests = None
|
||||||
|
|
||||||
|
|
||||||
# Django-guardian is optional. Import only if guardian is in INSTALLED_APPS
|
|
||||||
# Fixes (#1712). We keep the try/except for the test suite.
|
|
||||||
guardian = None
|
|
||||||
try:
|
|
||||||
if 'guardian' in settings.INSTALLED_APPS:
|
|
||||||
import guardian # noqa
|
|
||||||
except ImportError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
# PATCH method is not implemented by Django
|
# PATCH method is not implemented by Django
|
||||||
if 'patch' not in View.http_method_names:
|
if 'patch' not in View.http_method_names:
|
||||||
View.http_method_names = View.http_method_names + ['patch']
|
View.http_method_names = View.http_method_names + ['patch']
|
||||||
|
|
|
@ -16,7 +16,7 @@ from django.utils import six
|
||||||
from django.utils.encoding import force_text
|
from django.utils.encoding import force_text
|
||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
|
|
||||||
from rest_framework.compat import coreapi, coreschema, distinct, guardian
|
from rest_framework.compat import coreapi, coreschema, distinct
|
||||||
from rest_framework.settings import api_settings
|
from rest_framework.settings import api_settings
|
||||||
|
|
||||||
|
|
||||||
|
@ -282,7 +282,11 @@ class DjangoObjectPermissionsFilter(BaseFilterBackend):
|
||||||
has read object level permissions.
|
has read object level permissions.
|
||||||
"""
|
"""
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
assert guardian, 'Using DjangoObjectPermissionsFilter, but django-guardian is not installed'
|
try:
|
||||||
|
import guardian
|
||||||
|
except ImportError:
|
||||||
|
raise ImportError('Using DjangoObjectPermissionsFilter, but django-guardian is not installed')
|
||||||
|
self.guardian_version = guardian.VERSION
|
||||||
|
|
||||||
perm_format = '%(app_label)s.view_%(model_name)s'
|
perm_format = '%(app_label)s.view_%(model_name)s'
|
||||||
|
|
||||||
|
@ -300,7 +304,7 @@ class DjangoObjectPermissionsFilter(BaseFilterBackend):
|
||||||
'model_name': model_cls._meta.model_name
|
'model_name': model_cls._meta.model_name
|
||||||
}
|
}
|
||||||
permission = self.perm_format % kwargs
|
permission = self.perm_format % kwargs
|
||||||
if tuple(guardian.VERSION) >= (1, 3):
|
if tuple(self.guardian_version) >= (1, 3):
|
||||||
# Maintain behavior compatibility with versions prior to 1.3
|
# Maintain behavior compatibility with versions prior to 1.3
|
||||||
extra = {'accept_global_perms': False}
|
extra = {'accept_global_perms': False}
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -12,12 +12,16 @@ from rest_framework import (
|
||||||
HTTP_HEADER_ENCODING, authentication, generics, permissions, serializers,
|
HTTP_HEADER_ENCODING, authentication, generics, permissions, serializers,
|
||||||
status, views
|
status, views
|
||||||
)
|
)
|
||||||
from rest_framework.compat import guardian
|
|
||||||
from rest_framework.filters import DjangoObjectPermissionsFilter
|
from rest_framework.filters import DjangoObjectPermissionsFilter
|
||||||
from rest_framework.routers import DefaultRouter
|
from rest_framework.routers import DefaultRouter
|
||||||
from rest_framework.test import APIRequestFactory
|
from rest_framework.test import APIRequestFactory
|
||||||
from tests.models import BasicModel
|
from tests.models import BasicModel
|
||||||
|
|
||||||
|
try:
|
||||||
|
import guardian
|
||||||
|
except ImportError:
|
||||||
|
guardian = None
|
||||||
|
|
||||||
factory = APIRequestFactory()
|
factory = APIRequestFactory()
|
||||||
|
|
||||||
|
|
||||||
|
|
6
tox.ini
6
tox.ini
|
@ -27,8 +27,8 @@ deps =
|
||||||
django20: Django>=2.0,<2.1
|
django20: Django>=2.0,<2.1
|
||||||
django21: Django>=2.1b1,<2.2
|
django21: Django>=2.1b1,<2.2
|
||||||
djangomaster: https://github.com/django/django/archive/master.tar.gz
|
djangomaster: https://github.com/django/django/archive/master.tar.gz
|
||||||
|
optionals: -rrequirements/requirements-optionals.txt
|
||||||
-rrequirements/requirements-testing.txt
|
-rrequirements/requirements-testing.txt
|
||||||
-rrequirements/requirements-optionals.txt
|
|
||||||
|
|
||||||
[testenv:base]
|
[testenv:base]
|
||||||
; Ensure optional dependencies are not required
|
; Ensure optional dependencies are not required
|
||||||
|
@ -41,6 +41,10 @@ commands = ./runtests.py --fast {posargs} --no-pkgroot --staticfiles -rw
|
||||||
deps =
|
deps =
|
||||||
django
|
django
|
||||||
-rrequirements/requirements-testing.txt
|
-rrequirements/requirements-testing.txt
|
||||||
|
|
||||||
|
[testenv:dist-optionals]
|
||||||
|
commands = {[testenv:dist]commands}
|
||||||
|
deps = {[testenv:dist]deps}
|
||||||
-rrequirements/requirements-optionals.txt
|
-rrequirements/requirements-optionals.txt
|
||||||
|
|
||||||
[testenv:lint]
|
[testenv:lint]
|
||||||
|
|
Loading…
Reference in New Issue
Block a user