-
Notifications
You must be signed in to change notification settings - Fork 678
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
This is an attempt at fixing AppRegistryNotReady #175
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
from django.contrib.auth import models as auth_models | ||
from django.db.models.manager import EmptyManager | ||
from django.utils.functional import cached_property | ||
|
||
|
@@ -19,11 +18,13 @@ class instead of a `User` model instance. Instances of this class act as | |
# inactive user | ||
is_active = True | ||
|
||
_groups = EmptyManager(auth_models.Group) | ||
_user_permissions = EmptyManager(auth_models.Permission) | ||
|
||
def __init__(self, token): | ||
self.token = token | ||
from django.contrib.auth import models as auth_models | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since this is always used, it's best if the import is still left at the top for performance. |
||
self._groups = EmptyManager(auth_models.Group) | ||
self._user_permissions = EmptyManager(auth_models.Permission) | ||
|
||
|
||
def __str__(self): | ||
return 'TokenUser {}'.format(self.id) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
from django.contrib.auth import get_user_model | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Combine the import statements: |
||
from django.contrib.auth import authenticate | ||
from django.utils.translation import ugettext_lazy as _ | ||
from rest_framework import exceptions, serializers | ||
|
||
from .settings import api_settings | ||
from .state import User | ||
from .tokens import RefreshToken, SlidingToken, UntypedToken | ||
|
||
|
||
|
@@ -18,7 +18,9 @@ def __init__(self, *args, **kwargs): | |
|
||
|
||
class TokenObtainSerializer(serializers.Serializer): | ||
username_field = User.USERNAME_FIELD | ||
user_model = get_user_model() | ||
|
||
username_field = user_model.USERNAME_FIELD | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it really necessary to set a name "user_model" if it's only used once in L23? Just use |
||
|
||
default_error_messages = { | ||
'no_active_account': _('No active account found with the given credentials') | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,5 @@ | |
from .backends import TokenBackend | ||
from .settings import api_settings | ||
|
||
User = get_user_model() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove the unused import statement for get_user_model |
||
token_backend = TokenBackend(api_settings.ALGORITHM, api_settings.SIGNING_KEY, | ||
api_settings.VERIFYING_KEY, api_settings.AUDIENCE, api_settings.ISSUER) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd much rather see something above the class:
User = get_user_model()
than see what's being done here.