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
ff29fdd8
Commit
ff29fdd8
authored
Dec 30, 2015
by
S. Andrew Sheppard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
don't import authtoken model until needed
parent
af0ea8ef
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
9 additions
and
11 deletions
+9
-11
rest_framework/authentication.py
+9
-3
rest_framework/authtoken/models.py
+0
-8
No files found.
rest_framework/authentication.py
View file @
ff29fdd8
...
...
@@ -10,7 +10,6 @@ from django.middleware.csrf import CsrfViewMiddleware
from
django.utils.translation
import
ugettext_lazy
as
_
from
rest_framework
import
HTTP_HEADER_ENCODING
,
exceptions
from
rest_framework.authtoken.models
import
Token
def
get_authorization_header
(
request
):
...
...
@@ -149,7 +148,14 @@ class TokenAuthentication(BaseAuthentication):
Authorization: Token 401f7ac837da42b97f613d789819ff93537bee6a
"""
model
=
Token
model
=
None
def
get_model
(
self
):
if
self
.
model
is
not
None
:
return
self
.
model
from
rest_framework.authtoken.models
import
Token
return
Token
"""
A custom token model may be used, but must have the following properties.
...
...
@@ -180,7 +186,7 @@ class TokenAuthentication(BaseAuthentication):
def
authenticate_credentials
(
self
,
key
):
try
:
token
=
self
.
model
.
objects
.
select_related
(
'user'
)
.
get
(
key
=
key
)
token
=
self
.
get_model
()
.
objects
.
select_related
(
'user'
)
.
get
(
key
=
key
)
except
self
.
model
.
DoesNotExist
:
raise
exceptions
.
AuthenticationFailed
(
_
(
'Invalid token.'
))
...
...
rest_framework/authtoken/models.py
View file @
ff29fdd8
...
...
@@ -21,14 +21,6 @@ class Token(models.Model):
user
=
models
.
OneToOneField
(
AUTH_USER_MODEL
,
related_name
=
'auth_token'
)
created
=
models
.
DateTimeField
(
auto_now_add
=
True
)
class
Meta
:
# Work around for a bug in Django:
# https://code.djangoproject.com/ticket/19422
#
# Also see corresponding ticket:
# https://github.com/tomchristie/django-rest-framework/issues/705
abstract
=
'rest_framework.authtoken'
not
in
settings
.
INSTALLED_APPS
def
save
(
self
,
*
args
,
**
kwargs
):
if
not
self
.
key
:
self
.
key
=
self
.
generate_key
()
...
...
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