Skip to content

Conversation

@dedayoa
Copy link

@dedayoa dedayoa commented Jan 3, 2017

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.

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
def authenticate(self, **credentials):
UserModel = get_user_model()
self.username = credentials.get(get_user_model().USERNAME_FIELD)
self.username = credentials.get('username')
Copy link
Contributor

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.

Copy link
Author

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.

@@ -1,11 +1,12 @@
import threading
from django.utils.deprecation import MiddlewareMixin
Copy link
Contributor

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:

https://github.com/muccg/django-iprestrict/blob/4db839c123ae90afb82438cb500b5f3d54477ea9/iprestrict/middleware.py#L10

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

implemented this. Thanks

@@ -1,4 +1,5 @@
from django.db import models
from django.utils import datetime
Copy link
Contributor

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

Copy link
Author

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()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants