#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.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/052.bd9ac15c310c3fd769b52086b688241e%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to