Change username field widget in AuthenticationForm based on USERNAME_FIELD

181 views
Skip to first unread message

Anders Steinlein

unread,
Aug 2, 2013, 12:20:58 PM8/2/13
to django-d...@googlegroups.com
Hi all,

I have implemented a custom user model that extends AbstractBaseUser, where an EmailField is set as the USERNAME_FIELD. Logging in with a default auth login view and AuthenticationForm works nicely, however, the username field is still a CharField and thus rendered as a regular input field. I'm using Django 1.6 where I was expecting a type='email' input field.

How about we change the widget of the username field in AuthenticationForms __init__ method based on USERNAME_FIELD? If yes, would it be too late to sneak this into 1.6 given the new use of HTML5 input types? I'm happy to provide a patch.


Anders Steinlein
Eliksir AS

E-post: and...@e5r.no
Mobil: +47 926 13 069
Twitter: @asteinlein

ptone

unread,
Aug 5, 2013, 4:00:49 PM8/5/13
to django-d...@googlegroups.com
This seems like a reasonable change. I don't love the fact that the contrib.auth built in forms quasi support custom user models, as it leads to a less clear delineation about what parts of contrib.auth are tightly coupled auth the default User model.

https://docs.djangoproject.com/en/1.5/topics/auth/customizing/#custom-users-and-the-built-in-auth-forms

This doesn't warrant a backport for 1.6 though - as it is currently easy to override this in your own form, and 1.6 is in feature-freeze beta.

-Preston

Anders Steinlein

unread,
Aug 6, 2013, 8:32:08 AM8/6/13
to django-d...@googlegroups.com
On Mon, Aug 5, 2013 at 10:00 PM, ptone <pre...@ptone.com> wrote:
This seems like a reasonable change. I don't love the fact that the contrib.auth built in forms quasi support custom user models, as it leads to a less clear delineation about what parts of contrib.auth are tightly coupled auth the default User model.

OK, I'll go ahead and open a ticket and write a patch for this.

What kind of widgets for a username do you feel it's useful to support? I'm thinking NumberInput for integer fields, EmailInput for email fields, URLInput for URL fields, and TextInput for everything else.

/A.
Reply all
Reply to author
Forward
0 new messages