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
abbe9213
Commit
abbe9213
authored
Sep 23, 2013
by
Markus Kaiserswerth
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Address pending deprecation of Model._meta.module_name in Django 1.6
parent
0e58d4c7
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
16 additions
and
7 deletions
+16
-7
rest_framework/compat.py
+8
-0
rest_framework/filters.py
+2
-2
rest_framework/permissions.py
+4
-3
rest_framework/tests/test_permissions.py
+2
-2
No files found.
rest_framework/compat.py
View file @
abbe9213
...
@@ -80,6 +80,14 @@ except ImportError:
...
@@ -80,6 +80,14 @@ except ImportError:
Image
=
None
Image
=
None
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
def
get_concrete_model
(
model_cls
):
def
get_concrete_model
(
model_cls
):
try
:
try
:
return
model_cls
.
_meta
.
concrete_model
return
model_cls
.
_meta
.
concrete_model
...
...
rest_framework/filters.py
View file @
abbe9213
...
@@ -4,7 +4,7 @@ returned by list views.
...
@@ -4,7 +4,7 @@ returned by list views.
"""
"""
from
__future__
import
unicode_literals
from
__future__
import
unicode_literals
from
django.db
import
models
from
django.db
import
models
from
rest_framework.compat
import
django_filters
,
six
,
guardian
from
rest_framework.compat
import
django_filters
,
six
,
guardian
,
get_model_name
from
functools
import
reduce
from
functools
import
reduce
import
operator
import
operator
...
@@ -158,7 +158,7 @@ class DjangoObjectPermissionsFilter(BaseFilterBackend):
...
@@ -158,7 +158,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'
:
model_cls
.
_meta
.
module_name
'model_name'
:
get_model_name
(
model_cls
)
}
}
permission
=
self
.
perm_format
%
kwargs
permission
=
self
.
perm_format
%
kwargs
return
guardian
.
shortcuts
.
get_objects_for_user
(
user
,
permission
,
queryset
)
return
guardian
.
shortcuts
.
get_objects_for_user
(
user
,
permission
,
queryset
)
rest_framework/permissions.py
View file @
abbe9213
...
@@ -8,7 +8,8 @@ import warnings
...
@@ -8,7 +8,8 @@ import warnings
SAFE_METHODS
=
[
'GET'
,
'HEAD'
,
'OPTIONS'
]
SAFE_METHODS
=
[
'GET'
,
'HEAD'
,
'OPTIONS'
]
from
django.http
import
Http404
from
django.http
import
Http404
from
rest_framework.compat
import
oauth2_provider_scope
,
oauth2_constants
from
rest_framework.compat
import
(
get_model_name
,
oauth2_provider_scope
,
oauth2_constants
)
class
BasePermission
(
object
):
class
BasePermission
(
object
):
...
@@ -116,7 +117,7 @@ class DjangoModelPermissions(BasePermission):
...
@@ -116,7 +117,7 @@ class DjangoModelPermissions(BasePermission):
"""
"""
kwargs
=
{
kwargs
=
{
'app_label'
:
model_cls
.
_meta
.
app_label
,
'app_label'
:
model_cls
.
_meta
.
app_label
,
'model_name'
:
model_cls
.
_meta
.
module_name
'model_name'
:
get_model_name
(
model_cls
)
}
}
return
[
perm
%
kwargs
for
perm
in
self
.
perms_map
[
method
]]
return
[
perm
%
kwargs
for
perm
in
self
.
perms_map
[
method
]]
...
@@ -177,7 +178,7 @@ class DjangoObjectPermissions(DjangoModelPermissions):
...
@@ -177,7 +178,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'
:
model_cls
.
_meta
.
module_name
'model_name'
:
get_model_name
(
model_cls
)
}
}
return
[
perm
%
kwargs
for
perm
in
self
.
perms_map
[
method
]]
return
[
perm
%
kwargs
for
perm
in
self
.
perms_map
[
method
]]
...
...
rest_framework/tests/test_permissions.py
View file @
abbe9213
...
@@ -4,7 +4,7 @@ from django.db import models
...
@@ -4,7 +4,7 @@ from django.db import models
from
django.test
import
TestCase
from
django.test
import
TestCase
from
django.utils
import
unittest
from
django.utils
import
unittest
from
rest_framework
import
generics
,
status
,
permissions
,
authentication
,
HTTP_HEADER_ENCODING
from
rest_framework
import
generics
,
status
,
permissions
,
authentication
,
HTTP_HEADER_ENCODING
from
rest_framework.compat
import
guardian
from
rest_framework.compat
import
guardian
,
get_model_name
from
rest_framework.filters
import
DjangoObjectPermissionsFilter
from
rest_framework.filters
import
DjangoObjectPermissionsFilter
from
rest_framework.test
import
APIRequestFactory
from
rest_framework.test
import
APIRequestFactory
from
rest_framework.tests.models
import
BasicModel
from
rest_framework.tests.models
import
BasicModel
...
@@ -202,7 +202,7 @@ class ObjectPermissionsIntegrationTests(TestCase):
...
@@ -202,7 +202,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
=
BasicPermModel
.
_meta
.
module_name
model_name
=
get_model_name
(
BasicPermModel
)
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