-
Notifications
You must be signed in to change notification settings - Fork 19
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
Fixes here and there #13
base: master
Are you sure you want to change the base?
Conversation
Middleware has changed in django 1.10, see https://docs.djangoproject.com/en/1.10/topics/http/middleware/#upgrading-pre-django-1-10-style-middleware This mixin is just "band aid"
It happens that if USERNAME_FIELD is not 'username' like it usually isn't for custom user models, then self.username is None, leading to empty fields for username.
Getting the "username" should be done with get_username() otherwise an AttributeError is raised on custom user models with custom USERNAME_FIELD
Note to add useraudit to project urls file
Django complains when a naive datetime is saved into a DateTime model field. Fix to issue #1
useraudit/backend.py
Outdated
@@ -34,7 +34,7 @@ def __init__(self): | |||
|
|||
def authenticate(self, **credentials): | |||
UserModel = get_user_model() | |||
self.username = credentials.get(get_user_model().USERNAME_FIELD) | |||
self.username = credentials.get('username') |
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.
Why is this needed?
The current version seems more flexible to me.
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.
in retrospect, I can seem to remember why.
useraudit/middleware.py
Outdated
@@ -1,11 +1,12 @@ | |||
import threading | |||
from django.utils.deprecation import MiddlewareMixin |
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.
This will fail on pre 1.10 Django.
you should do something along these lines:
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.
implemented this. Thanks
useraudit/models.py
Outdated
@@ -1,4 +1,5 @@ | |||
from django.db import models | |||
from django.utils import datetime |
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 like the change but shouldn't this be?
from django.utils import timezone
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.
yes indeed, it should.
import from django.utils should have been timezone, not datetime
Make 1.10 compatible without breaking pre 1.10
reverted to get the USERNAME_FIELD off get_user_model()
These fixes are without automated tests. Although I don't think anything is 1.10 specific, but I made these fixes against 1.10...since most will probably still be running 1.9.
Most of this came to the fore because I'm using a custom user model.