Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
django-rest-framework
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
django-rest-framework
Commits
25de8c96
Commit
25de8c96
authored
Sep 21, 2015
by
Carlton Gibson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove Django 1.5 get_model_name fallback
parent
4a1ab3c1
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
6 additions
and
18 deletions
+6
-18
rest_framework/compat.py
+0
-8
rest_framework/filters.py
+2
-4
rest_framework/permissions.py
+2
-4
tests/test_permissions.py
+2
-2
No files found.
rest_framework/compat.py
View file @
25de8c96
...
@@ -127,14 +127,6 @@ except ImportError:
...
@@ -127,14 +127,6 @@ except ImportError:
pass
pass
def
get_model_name
(
model_cls
):
try
:
return
model_cls
.
_meta
.
model_name
except
AttributeError
:
# < 1.6 used module_name instead of model_name
return
model_cls
.
_meta
.
module_name
# MinValueValidator, MaxValueValidator et al. only accept `message` in 1.8+
# MinValueValidator, MaxValueValidator et al. only accept `message` in 1.8+
if
django
.
VERSION
>=
(
1
,
8
):
if
django
.
VERSION
>=
(
1
,
8
):
from
django.core.validators
import
MinValueValidator
,
MaxValueValidator
from
django.core.validators
import
MinValueValidator
,
MaxValueValidator
...
...
rest_framework/filters.py
View file @
25de8c96
...
@@ -11,9 +11,7 @@ from django.core.exceptions import ImproperlyConfigured
...
@@ -11,9 +11,7 @@ from django.core.exceptions import ImproperlyConfigured
from
django.db
import
models
from
django.db
import
models
from
django.utils
import
six
from
django.utils
import
six
from
rest_framework.compat
import
(
from
rest_framework.compat
import
distinct
,
django_filters
,
guardian
distinct
,
django_filters
,
get_model_name
,
guardian
)
from
rest_framework.settings
import
api_settings
from
rest_framework.settings
import
api_settings
FilterSet
=
django_filters
and
django_filters
.
FilterSet
or
None
FilterSet
=
django_filters
and
django_filters
.
FilterSet
or
None
...
@@ -202,7 +200,7 @@ class DjangoObjectPermissionsFilter(BaseFilterBackend):
...
@@ -202,7 +200,7 @@ class DjangoObjectPermissionsFilter(BaseFilterBackend):
model_cls
=
queryset
.
model
model_cls
=
queryset
.
model
kwargs
=
{
kwargs
=
{
'app_label'
:
model_cls
.
_meta
.
app_label
,
'app_label'
:
model_cls
.
_meta
.
app_label
,
'model_name'
:
get_model_name
(
model_cls
)
'model_name'
:
model_cls
.
_meta
.
model_name
}
}
permission
=
self
.
perm_format
%
kwargs
permission
=
self
.
perm_format
%
kwargs
if
guardian
.
VERSION
>=
(
1
,
3
):
if
guardian
.
VERSION
>=
(
1
,
3
):
...
...
rest_framework/permissions.py
View file @
25de8c96
...
@@ -5,8 +5,6 @@ from __future__ import unicode_literals
...
@@ -5,8 +5,6 @@ from __future__ import unicode_literals
from
django.http
import
Http404
from
django.http
import
Http404
from
rest_framework.compat
import
get_model_name
SAFE_METHODS
=
(
'GET'
,
'HEAD'
,
'OPTIONS'
)
SAFE_METHODS
=
(
'GET'
,
'HEAD'
,
'OPTIONS'
)
...
@@ -104,7 +102,7 @@ class DjangoModelPermissions(BasePermission):
...
@@ -104,7 +102,7 @@ class DjangoModelPermissions(BasePermission):
"""
"""
kwargs
=
{
kwargs
=
{
'app_label'
:
model_cls
.
_meta
.
app_label
,
'app_label'
:
model_cls
.
_meta
.
app_label
,
'model_name'
:
get_model_name
(
model_cls
)
'model_name'
:
model_cls
.
_meta
.
model_name
}
}
return
[
perm
%
kwargs
for
perm
in
self
.
perms_map
[
method
]]
return
[
perm
%
kwargs
for
perm
in
self
.
perms_map
[
method
]]
...
@@ -166,7 +164,7 @@ class DjangoObjectPermissions(DjangoModelPermissions):
...
@@ -166,7 +164,7 @@ class DjangoObjectPermissions(DjangoModelPermissions):
def
get_required_object_permissions
(
self
,
method
,
model_cls
):
def
get_required_object_permissions
(
self
,
method
,
model_cls
):
kwargs
=
{
kwargs
=
{
'app_label'
:
model_cls
.
_meta
.
app_label
,
'app_label'
:
model_cls
.
_meta
.
app_label
,
'model_name'
:
get_model_name
(
model_cls
)
'model_name'
:
model_cls
.
_meta
.
model_name
}
}
return
[
perm
%
kwargs
for
perm
in
self
.
perms_map
[
method
]]
return
[
perm
%
kwargs
for
perm
in
self
.
perms_map
[
method
]]
...
...
tests/test_permissions.py
View file @
25de8c96
...
@@ -11,7 +11,7 @@ from rest_framework import (
...
@@ -11,7 +11,7 @@ from rest_framework import (
HTTP_HEADER_ENCODING
,
authentication
,
generics
,
permissions
,
serializers
,
HTTP_HEADER_ENCODING
,
authentication
,
generics
,
permissions
,
serializers
,
status
status
)
)
from
rest_framework.compat
import
g
et_model_name
,
g
uardian
,
unittest
from
rest_framework.compat
import
guardian
,
unittest
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
...
@@ -278,7 +278,7 @@ class ObjectPermissionsIntegrationTests(TestCase):
...
@@ -278,7 +278,7 @@ class ObjectPermissionsIntegrationTests(TestCase):
# give everyone model level permissions, as we are not testing those
# give everyone model level permissions, as we are not testing those
everyone
=
Group
.
objects
.
create
(
name
=
'everyone'
)
everyone
=
Group
.
objects
.
create
(
name
=
'everyone'
)
model_name
=
get_model_name
(
BasicPermModel
)
model_name
=
BasicPermModel
.
_meta
.
model_name
app_label
=
BasicPermModel
.
_meta
.
app_label
app_label
=
BasicPermModel
.
_meta
.
app_label
f
=
'{0}_{1}'
.
format
f
=
'{0}_{1}'
.
format
perms
=
{
perms
=
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment