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
cafc00b8
Commit
cafc00b8
authored
Nov 19, 2012
by
Tom Christie
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #424 from jonlil/master
Support for django 1.5a (auth_user_model)
parents
ce5b186c
acc425e7
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
27 additions
and
4 deletions
+27
-4
rest_framework/authtoken/migrations/0001_initial.py
+11
-3
rest_framework/authtoken/models.py
+2
-1
rest_framework/compat.py
+14
-0
No files found.
rest_framework/authtoken/migrations/0001_initial.py
View file @
cafc00b8
...
@@ -5,13 +5,21 @@ from south.v2 import SchemaMigration
...
@@ -5,13 +5,21 @@ from south.v2 import SchemaMigration
from
django.db
import
models
from
django.db
import
models
try
:
from
django.contrib.auth
import
get_user_model
except
ImportError
:
# django < 1.5
from
django.contrib.auth.models
import
User
else
:
User
=
get_user_model
()
class
Migration
(
SchemaMigration
):
class
Migration
(
SchemaMigration
):
def
forwards
(
self
,
orm
):
def
forwards
(
self
,
orm
):
# Adding model 'Token'
# Adding model 'Token'
db
.
create_table
(
'authtoken_token'
,
(
db
.
create_table
(
'authtoken_token'
,
(
(
'key'
,
self
.
gf
(
'django.db.models.fields.CharField'
)(
max_length
=
40
,
primary_key
=
True
)),
(
'key'
,
self
.
gf
(
'django.db.models.fields.CharField'
)(
max_length
=
40
,
primary_key
=
True
)),
(
'user'
,
self
.
gf
(
'django.db.models.fields.related.OneToOneField'
)(
related_name
=
'auth_token'
,
unique
=
True
,
to
=
orm
[
'
auth.User'
])),
(
'user'
,
self
.
gf
(
'django.db.models.fields.related.OneToOneField'
)(
related_name
=
'auth_token'
,
unique
=
True
,
to
=
orm
[
'
%
s.
%
s'
%
(
User
.
_meta
.
app_label
,
User
.
_meta
.
object_name
)
])),
(
'created'
,
self
.
gf
(
'django.db.models.fields.DateTimeField'
)(
auto_now_add
=
True
,
blank
=
True
)),
(
'created'
,
self
.
gf
(
'django.db.models.fields.DateTimeField'
)(
auto_now_add
=
True
,
blank
=
True
)),
))
))
db
.
send_create_signal
(
'authtoken'
,
[
'Token'
])
db
.
send_create_signal
(
'authtoken'
,
[
'Token'
])
...
@@ -36,7 +44,7 @@ class Migration(SchemaMigration):
...
@@ -36,7 +44,7 @@ class Migration(SchemaMigration):
'id'
:
(
'django.db.models.fields.AutoField'
,
[],
{
'primary_key'
:
'True'
}),
'id'
:
(
'django.db.models.fields.AutoField'
,
[],
{
'primary_key'
:
'True'
}),
'name'
:
(
'django.db.models.fields.CharField'
,
[],
{
'max_length'
:
'50'
})
'name'
:
(
'django.db.models.fields.CharField'
,
[],
{
'max_length'
:
'50'
})
},
},
'auth.user'
:
{
"
%
s.
%
s"
%
(
User
.
_meta
.
app_label
,
User
.
_meta
.
module_name
)
:
{
'Meta'
:
{
'object_name'
:
'User'
},
'Meta'
:
{
'object_name'
:
'User'
},
'date_joined'
:
(
'django.db.models.fields.DateTimeField'
,
[],
{
'default'
:
'datetime.datetime.now'
}),
'date_joined'
:
(
'django.db.models.fields.DateTimeField'
,
[],
{
'default'
:
'datetime.datetime.now'
}),
'email'
:
(
'django.db.models.fields.EmailField'
,
[],
{
'max_length'
:
'75'
,
'blank'
:
'True'
}),
'email'
:
(
'django.db.models.fields.EmailField'
,
[],
{
'max_length'
:
'75'
,
'blank'
:
'True'
}),
...
@@ -56,7 +64,7 @@ class Migration(SchemaMigration):
...
@@ -56,7 +64,7 @@ class Migration(SchemaMigration):
'Meta'
:
{
'object_name'
:
'Token'
},
'Meta'
:
{
'object_name'
:
'Token'
},
'created'
:
(
'django.db.models.fields.DateTimeField'
,
[],
{
'auto_now_add'
:
'True'
,
'blank'
:
'True'
}),
'created'
:
(
'django.db.models.fields.DateTimeField'
,
[],
{
'auto_now_add'
:
'True'
,
'blank'
:
'True'
}),
'key'
:
(
'django.db.models.fields.CharField'
,
[],
{
'max_length'
:
'40'
,
'primary_key'
:
'True'
}),
'key'
:
(
'django.db.models.fields.CharField'
,
[],
{
'max_length'
:
'40'
,
'primary_key'
:
'True'
}),
'user'
:
(
'django.db.models.fields.related.OneToOneField'
,
[],
{
'related_name'
:
"'auth_token'"
,
'unique'
:
'True'
,
'to'
:
"orm['
auth.User']"
})
'user'
:
(
'django.db.models.fields.related.OneToOneField'
,
[],
{
'related_name'
:
"'auth_token'"
,
'unique'
:
'True'
,
'to'
:
"orm['
%
s.
%
s']"
%
(
User
.
_meta
.
app_label
,
User
.
_meta
.
object_name
)
})
},
},
'contenttypes.contenttype'
:
{
'contenttypes.contenttype'
:
{
'Meta'
:
{
'ordering'
:
"('name',)"
,
'unique_together'
:
"(('app_label', 'model'),)"
,
'object_name'
:
'ContentType'
,
'db_table'
:
"'django_content_type'"
},
'Meta'
:
{
'ordering'
:
"('name',)"
,
'unique_together'
:
"(('app_label', 'model'),)"
,
'object_name'
:
'ContentType'
,
'db_table'
:
"'django_content_type'"
},
...
...
rest_framework/authtoken/models.py
View file @
cafc00b8
import
uuid
import
uuid
import
hmac
import
hmac
from
hashlib
import
sha1
from
hashlib
import
sha1
from
rest_framework.compat
import
User
from
django.db
import
models
from
django.db
import
models
...
@@ -9,7 +10,7 @@ class Token(models.Model):
...
@@ -9,7 +10,7 @@ class Token(models.Model):
The default authorization token model.
The default authorization token model.
"""
"""
key
=
models
.
CharField
(
max_length
=
40
,
primary_key
=
True
)
key
=
models
.
CharField
(
max_length
=
40
,
primary_key
=
True
)
user
=
models
.
OneToOneField
(
'auth.User'
,
related_name
=
'auth_token'
)
user
=
models
.
OneToOneField
(
User
,
related_name
=
'auth_token'
)
created
=
models
.
DateTimeField
(
auto_now_add
=
True
)
created
=
models
.
DateTimeField
(
auto_now_add
=
True
)
def
save
(
self
,
*
args
,
**
kwargs
):
def
save
(
self
,
*
args
,
**
kwargs
):
...
...
rest_framework/compat.py
View file @
cafc00b8
...
@@ -27,6 +27,20 @@ def get_concrete_model(model_cls):
...
@@ -27,6 +27,20 @@ def get_concrete_model(model_cls):
return
model_cls
return
model_cls
# Django 1.5 add support for custom auth user model
if
django
.
VERSION
>=
(
1
,
5
):
from
django.conf
import
settings
if
hasattr
(
settings
,
'AUTH_USER_MODEL'
):
User
=
settings
.
AUTH_USER_MODEL
else
:
from
django.contrib.auth.models
import
User
else
:
try
:
from
django.contrib.auth.models
import
User
except
ImportError
:
raise
ImportError
(
u"User model is not to be found."
)
# First implementation of Django class-based views did not include head method
# First implementation of Django class-based views did not include head method
# in base View class - https://code.djangoproject.com/ticket/15668
# in base View class - https://code.djangoproject.com/ticket/15668
if
django
.
VERSION
>=
(
1
,
4
):
if
django
.
VERSION
>=
(
1
,
4
):
...
...
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