Opened 16 years ago
Closed 14 years ago
#9598 closed (wontfix)
`
Reported by: | Owned by: | nobody | |
---|---|---|---|
Component: | contrib.auth | Version: | 1.0 |
Severity: | Keywords: | ||
Cc: | Triage Stage: | Design decision needed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
contrib/auth/models.py:
class UserManager(models.Manager): def create_user(self, username, email, password=None): "Creates and saves a User with the given username, e-mail and password." now = datetime.datetime.now() user = self.model(None, username, '', '', email.strip().lower(), 'placeholder', False, True, False, now, now) if password: user.set_password(password) else: user.set_unusable_password() user.save() return user
This should support keyword arguments for first_name, last_name etc. That would make user-creating code cleaner and would avoid unnecessary database operations. The change is so obvious I’m not including a patch.
Are there any reasons not to add such a feature?
Change History (5)
comment:1 by , 16 years ago
comment:2 by , 16 years ago
Triage Stage: | Unreviewed → Design decision needed |
---|
comment:3 by , 16 years ago
-1 for the change. Can already be achieved with
user = User(**kwargs) user.set_password('password') user.save()
comment:4 by , 16 years ago
dc, I think you’re missing the point. From your reasoning one might conclude the create_user method should be removed as well, and maybe Django should not exist because Web sites can already be achieved with other means? Python is a great language because it allows concise code, and having one statement do the job of three would be beneficial IMO.
Alternate proposal
On second thoughts, I’ve come up with a solution which is closer to Django spirit. What’s the problem with create_user? Its save() is needless if more fields are to be populated. So let’s just add a ‘commit’ argument, default True, that would control whether save() is called. This would be immediately familiar to any Django user.
At the same time, additional arguments don’t really hinder one’s ability to memorise. One has to memorise when one needs things that don’t work, not when one doesn’t need things that would work.
comment:5 by , 14 years ago
Resolution: | → wontfix |
---|---|
Status: | new → closed |
Summary: | create_user should allow specifying more fields → ` |
Not worth the change. As noted above, if you want to control everything, just create the user model directly and call set_password
. The issue of why then to keep create_user
is moot. It causes no harm (and is used in many places) by being there, so it's not going away.
At that point it's no different form
create()
with a call toset_password()
, so you might as well use that version if you need to add all the extra fields. I'm in favour of keepingcreate_user()
nice and simple to document and memorise.