[Django] #28706: Allow easier reuse of AuthenticationForm invalid_login ValidationError

4 views
Skip to first unread message

Django

unread,
Oct 12, 2017, 12:46:33 AM10/12/17
to django-...@googlegroups.com
#28706: Allow easier reuse of AuthenticationForm invalid_login ValidationError
----------------------------------------+------------------------
Reporter: Jon Dufresne | Owner: nobody
Type: New feature | Status: new
Component: contrib.auth | Version: master
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
----------------------------------------+------------------------
The `AuthenticationForm` contains the
[https://github.com/django/django/blob/4d60261b2a77460b4c127c3d832518b95e11a0ac/django/contrib/auth/forms.py#L190-L205
snippet in the clean method]:

{{{
def clean(self):
username = self.cleaned_data.get('username')
password = self.cleaned_data.get('password')

if ...:
...
if ... is None:
raise forms.ValidationError(
self.error_messages['invalid_login'],
code='invalid_login',
params={'username': self.username_field.verbose_name},
)
...
}}}

In my project, I have overridden `AuthenticationForm` with customizations.
Among these customizations, I have other reasons for raising an
`invalid_login`. Rather than copy round the:

{{{
raise forms.ValidationError(
self.error_messages['invalid_login'],
code='invalid_login',
params={'username': self.username_field.verbose_name},
)
}}}

I suggest the form wrap this in a small function for reuse.

I'm not sure if this requires documentation or can remain an internal
implementation detail. I'm happy to also add documentation if it is a good
idea.

--
Ticket URL: <https://code.djangoproject.com/ticket/28706>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Oct 12, 2017, 12:48:23 AM10/12/17
to django-...@googlegroups.com
#28706: Allow easier reuse of AuthenticationForm invalid_login ValidationError
------------------------------+--------------------------------------

Reporter: Jon Dufresne | Owner: nobody
Type: New feature | Status: new
Component: contrib.auth | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------------+--------------------------------------
Changes (by Jon Dufresne):

* has_patch: 0 => 1


Comment:

[https://github.com/django/django/pull/9231 PR]

--
Ticket URL: <https://code.djangoproject.com/ticket/28706#comment:1>

Django

unread,
Oct 12, 2017, 1:59:02 PM10/12/17
to django-...@googlegroups.com
#28706: Allow easier reuse of AuthenticationForm invalid_login ValidationError
-------------------------------------+-------------------------------------

Reporter: Jon Dufresne | Owner: nobody
Type: | Status: new
Cleanup/optimization |
Component: contrib.auth | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Claude Paroz):

* type: New feature => Cleanup/optimization
* stage: Unreviewed => Ready for checkin


Comment:

Looks good, I don't think documentation is required here.

--
Ticket URL: <https://code.djangoproject.com/ticket/28706#comment:2>

Django

unread,
Oct 23, 2017, 9:54:11 AM10/23/17
to django-...@googlegroups.com
#28706: Allow easier reuse of AuthenticationForm invalid_login ValidationError
-------------------------------------+-------------------------------------

Reporter: Jon Dufresne | Owner: nobody
Type: | Status: closed
Cleanup/optimization |
Component: contrib.auth | Version: master
Severity: Normal | Resolution: fixed

Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham <timograham@…>):

* status: new => closed
* resolution: => fixed


Comment:

In [changeset:"6ed347d8518e23d7e453bdb21f7fa59ce2c4a885" 6ed347d]:
{{{
#!CommitTicketReference repository=""
revision="6ed347d8518e23d7e453bdb21f7fa59ce2c4a885"
Fixed #28706 -- Moved AuthenticationFormn invalid login ValidationError to
a method for reuse.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/28706#comment:3>

Reply all
Reply to author
Forward
0 new messages