Django 1.5 Feature Suggestion

84 views
Skip to first unread message

JJ Zolper

unread,
Jul 26, 2013, 10:43:22 AM7/26/13
to django...@googlegroups.com
Hello everyone,

So I want to say thanks to the Django guys for providing more support for those of us that want to use a user's email as the UID and login handler versus the previous method of handling based on the username. I and probably many others appreciate the effort given to the topic and that it was integrated into Django 1.5.

Today I would like to request a continuing expansion about this concept.

In referencing this link:


I would like to request that if we want to make email the UID we don't have to do things such as:

class MyUser(AbstractBaseUser, PermissionsMixin):
    ....
    is_staff = models.BooleanField('staff status', default=False,
        help_text='Designates whether the user can log into this admin '
                    'site.')
    is_active = models.BooleanField('active', default=True,
        help_text='Designates whether this user should be treated as '
                    'active. Unselect this instead of deleting accounts.')
 
    def get_full_name(self):
        full_name = '%s %s' % (self.first_name, self.last_name)
        return full_name.strip()
 
    def get_short_name(self):
        return self.first_name

just to retain what could already be apart of Django. You guys know more about Django then I ever will and what the best way is to go about it but if we can eliminate additional code that is already in Django that would be wonderful.

Now in referencing:


Basically what I'm saying is, we shouldn't have to do what this fellow had to do:

Unfortunately there's nothing within django.contrib.auth that you can simply subclass to get a model that has

  1. email address in place of user name and

  2. works nicely with other django.contrib.auth-stuff, like groups.

The simplest approach is to copy models.pyadmin.py and forms.py fromdjango.contrib.auth, rip out user name all over the place and put in email address in it's place. I've done just that and I'm using it successfully in a couple of client projects.

I've put it up on github and pypi so you can install it with

pip install django-libtech-emailuser

I thank you for your time and I appreciate your consideration for integrating this once and for all into Django.

JJ Zolper



Russell Keith-Magee

unread,
Jul 26, 2013, 9:21:04 PM7/26/13
to django...@googlegroups.com
Hi JJ,
 
That's a fair comment -- "Email address as username" is a sufficiently common use case that it probably warrants being included in Django's core. I think I've overheard Jacob endorsing the same thing at some point in the past (although I'll stand corrected on this if I misheard/misunderstood/misattributed his comments). 

If you've already done the heavy lifting here, then all we need to do is massage your external package into contrib. Open a ticket and we can see what we can do about getting this in for 1.7.

Yours,
Russ Magee %-)


JJ Zolper

unread,
Jul 29, 2013, 8:37:49 PM7/29/13
to django...@googlegroups.com
Russell Keith-Magee,

Are you the one who is doing "Getting Started With Django" ? Sorry for getting off topic but just was curious. If so I donated money to that project and I am glad you are doing it.

Yes, that's what it seems to be called by other Django devs, "Email address as username." I prefer more to think of it as just "Email" with the same exact login handlign as "Username." That's my goal with this post is keep pushing until the point is reached where we can just call it "Email" login. I also think it is such a common case that it should be within Django's core. It is obvious from the large number of posts online about replacing the username with an email. If you have heard Jacob discussing it before, that would be wonderful! It would be awesome if the Django guys accepted this into Django all together. Given it must be considered with the release of Django 1.5 they did give a lot more support to people like me trying to have the email as the username through things like:

class CustomUser(AbstractBaseUser, PermissionsMixin):
     ....
     email = models.EmailField(max_length=255, unique=True)
     ....

     objects = CustomUserManager()

     USERNAME_FIELD = 'email'

So maybe Jacob and Adrian are already on top of this. The only thing I have been trying to do is follow the suggestions of those posts I have found online. I could surely route some possible people I think might have already banged this out but I'm not sure I'm the best bet. However, I did go ahead and open a ticket:


Thanks again to all the Django developers for their hard work,

JJ

Russell Keith-Magee

unread,
Jul 29, 2013, 9:07:43 PM7/29/13
to django...@googlegroups.com
On Tue, Jul 30, 2013 at 8:37 AM, JJ Zolper <codin...@gmail.com> wrote:
Russell Keith-Magee,

Are you the one who is doing "Getting Started With Django" ? Sorry for getting off topic but just was curious. If so I donated money to that project and I am glad you are doing it.

Sorry, that's not me. You're thinking of Kenneth Love (@kennethlove on twitter).
 
Yes, that's what it seems to be called by other Django devs, "Email address as username." I prefer more to think of it as just "Email" with the same exact login handlign as "Username." That's my goal with this post is keep pushing until the point is reached where we can just call it "Email" login. I also think it is such a common case that it should be within Django's core. It is obvious from the large number of posts online about replacing the username with an email.

A lot of those posts will be from pre-1.5 days; having the ability to easily use an email address as a username was one of the primary motivations behind introducing swappable users as a new feature. It was always possible; in Django 1.5, it's a lot easier; the next step is to make it trivial by having a custom user model for that purpose available in the box.

If you have heard Jacob discussing it before, that would be wonderful! It would be awesome if the Django guys accepted this into Django all together. Given it must be considered with the release of Django 1.5 they did give a lot more support to people like me trying to have the email as the username through things like:

class CustomUser(AbstractBaseUser, PermissionsMixin):
     ....
     email = models.EmailField(max_length=255, unique=True)
     ....

     objects = CustomUserManager()

     USERNAME_FIELD = 'email'

So maybe Jacob and Adrian are already on top of this.

Jacob and Adrian are only "on top of it" in the sense that Jacob has said it's a good idea. I wouldn't hang around waiting for either of them to commit such a patch -- they're both busy, and don't spend a lot of time committing to Django itself these days. 
 
The only thing I have been trying to do is follow the suggestions of those posts I have found online. I could surely route some possible people I think might have already banged this out but I'm not sure I'm the best bet. However, I did go ahead and open a ticket:


Thanks again to all the Django developers for their hard work,

Thanks for opening a ticket and driving the discussion. I've added some comments to the ticket and marked it as accepted; next step is a patch :-)

Yours,
Russ Magee %-)

JJ Zolper

unread,
Jul 30, 2013, 12:26:34 AM7/30/13
to django...@googlegroups.com
Oh that's right it was Kenneth, not sure why I thought it was you.

That's a good point about 1.5. That's sort of where I was going. I agree that everything is headed in the right direction.

And I'm sure they are busy. I can only imagine.

No problem on opening the ticket and getting it started and yes I see your comments thanks for that. And yes now it's time for the patch.

I will begin working on it. I will see what I can do. If anyone is willing to help don't hesitate to send them my way. I can be e-mailed at: jjzo...@madtrak.com. I haven't developed for the Django internals before so I'm completely new to all of this and I haven't been programming in Python or Django for a significant amount of time but I feel like I can make this happen. Hopefully others will be wanting to help along the way and I'm sure your coordinating support will be critical if you are able to help.

JJ

JJ Zolper

unread,
Jul 30, 2013, 12:53:40 AM7/30/13
to django...@googlegroups.com
Russell Keith-Magee,

This came to mind, before in my post I described a package I had come across that someone had made as their fix.

In quoting his github:

"There's a number apps out there for doing authentication with emailaddresses prior to Django 1.5. With the advent of Django 1.5 the Django core team has made it very easy to use any model for authentication simply by setting AUTH_USER_MODEL. Unfortunately it's not possible to create a EmailUser model by simply subclassing the User class in django.contrib.auth.models instead if you want a model that plays nicely with the rest of django.contrib.auth the simplest way is to copy all the code in django.contrib.auth.models.User and substitute username for emailaddress. You also need to edit some other minor stuff in forms.py and admin.py. This Django app does just that. I'm using it in production for a couple of client sites and it works fine."

Rewriting code that exists never did anyone any good. It seems he just stripped out the previous auth and replaced it with the email address. I feel like it should at least be given a look because maybe his work can be reviewed, tweaked if needed, verified, and ultimately merged into Django?

Thanks,

JJ

JJ Zolper

unread,
Jul 30, 2013, 12:58:46 AM7/30/13
to django...@googlegroups.com
My apologies for not making this quickly accessible. I meant to stick the link in there but it didn't make it into my previous post. It's been a long day. Here it is:


JJ

JJ Zolper

unread,
Aug 16, 2013, 8:05:50 PM8/16/13
to django...@googlegroups.com
I didn't want to clutter up the ticket that much so I thought we could discuss through here. Do you think the following package:


Could be used to merge in a solution to the django core for this?

It sounds like when this package was created it was fairly simple to "rename" the necessary parts so that it would operate as desired. Maybe this package could be reviewed, and moved into the contrib app like you said?

Thanks,

JJ
Reply all
Reply to author
Forward
0 new messages