Corrected some indentation in docs/topics/auth/default.txt.

This commit is contained in:
Tim Graham 2014-06-10 09:18:58 -04:00
parent 9560dac3c0
commit 34f4fd7024
1 changed files with 30 additions and 30 deletions

View File

@ -1099,12 +1099,12 @@ patterns.
* ``template_name``: The full name of a template to display the view. * ``template_name``: The full name of a template to display the view.
Defaults to :file:`registration/password_reset_complete.html`. Defaults to :file:`registration/password_reset_complete.html`.
* ``current_app``: A hint indicating which application contains the current * ``current_app``: A hint indicating which application contains the current
view. See the :ref:`namespaced URL resolution strategy view. See the :ref:`namespaced URL resolution strategy
<topics-http-reversing-url-namespaces>` for more information. <topics-http-reversing-url-namespaces>` for more information.
* ``extra_context``: A dictionary of context data that will be added to the * ``extra_context``: A dictionary of context data that will be added to the
default context data passed to the template. default context data passed to the template.
Helper functions Helper functions
---------------- ----------------
@ -1164,37 +1164,37 @@ provides several built-in forms located in :mod:`django.contrib.auth.forms`:
.. method:: confirm_login_allowed(user) .. method:: confirm_login_allowed(user)
.. versionadded:: 1.7 .. versionadded:: 1.7
By default, ``AuthenticationForm`` rejects users whose ``is_active`` flag By default, ``AuthenticationForm`` rejects users whose ``is_active`` flag
is set to ``False``. You may override this behavior with a custom policy to is set to ``False``. You may override this behavior with a custom policy to
determine which users can log in. Do this with a custom form that subclasses determine which users can log in. Do this with a custom form that subclasses
``AuthenticationForm`` and overrides the ``confirm_login_allowed`` method. ``AuthenticationForm`` and overrides the ``confirm_login_allowed`` method.
This method should raise a :exc:`~django.core.exceptions.ValidationError` This method should raise a :exc:`~django.core.exceptions.ValidationError`
if the given user may not log in. if the given user may not log in.
For example, to allow all users to log in, regardless of "active" status:: For example, to allow all users to log in, regardless of "active" status::
from django.contrib.auth.forms import AuthenticationForm from django.contrib.auth.forms import AuthenticationForm
class AuthenticationFormWithInactiveUsersOkay(AuthenticationForm): class AuthenticationFormWithInactiveUsersOkay(AuthenticationForm):
def confirm_login_allowed(self, user): def confirm_login_allowed(self, user):
pass pass
Or to allow only some active users to log in:: Or to allow only some active users to log in::
class PickyAuthenticationForm(AuthenticationForm): class PickyAuthenticationForm(AuthenticationForm):
def confirm_login_allowed(self, user): def confirm_login_allowed(self, user):
if not user.is_active: if not user.is_active:
raise forms.ValidationError( raise forms.ValidationError(
_("This account is inactive."), _("This account is inactive."),
code='inactive', code='inactive',
) )
if user.username.startswith('b'): if user.username.startswith('b'):
raise forms.ValidationError( raise forms.ValidationError(
_("Sorry, accounts starting with 'b' aren't welcome here."), _("Sorry, accounts starting with 'b' aren't welcome here."),
code='no_b_users', code='no_b_users',
) )
.. class:: PasswordChangeForm .. class:: PasswordChangeForm