Opened 3 years ago

Closed 3 years ago

Last modified 3 years ago

#19632 closed Cleanup/optimization (fixed)

Sample code is wrong in page: "Using the Django authentication system"

Reported by: grossmanandy@… Owned by: charettes
Component: Documentation Version: 1.4
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: yes
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description

In https://docs.djangoproject.com/en/dev/topics/auth/default/#auth-web-requests

from django.contrib.auth.decorators import user_passes_test

def email_check(user):
    return '@example.com' in request.user.email

@user_passes_test(email_check)
def my_view(request):
    ...

should read

from django.contrib.auth.decorators import user_passes_test

def email_check(request):
    return '@example.com' in request.user.email

@user_passes_test(email_check)
def my_view(request):
    ...

Attachments (1)

0001-Fixed-19632-Corrected-the-auth-documentation-concern.patch (896 bytes) - added by charettes 3 years ago.

Download all attachments as: .zip

Change History (7)

comment:1 Changed 3 years ago by charettes

  • Needs documentation set
  • Needs tests unset
  • Owner changed from nobody to charettes
  • Patch needs improvement unset
  • Status changed from new to assigned
  • Triage Stage changed from Unreviewed to Accepted
  • Type changed from Bug to Cleanup/optimization

comment:2 Changed 3 years ago by charettes

Actually looking at @user_passes_test the doc should read:

from django.contrib.auth.decorators import user_passes_test

def email_check(user):
    return '@example.com' in user.email

@user_passes_test(email_check)
def my_view(request):
    ...

Since the test function is called with request.user.

comment:3 Changed 3 years ago by charettes

  • Has patch set

Added the doc fix.

comment:4 Changed 3 years ago by Aymeric Augustin <aymeric.augustin@…>

  • Resolution set to fixed
  • Status changed from assigned to closed

In d90abcc9dad9b239e77aa67bfdd0c431072e2434:

[1.5.x] Fixed #19632 -- Bug in code sample.

Thanks grossmanandy at bfusa com and Simon Charette.

Backport of 1dd7492.

comment:5 Changed 3 years ago by Aymeric Augustin <aymeric.augustin@…>

In 1dd749284325ea8fe747a3728ed92bafef4ff6a0:

Fixed #19632 -- Bug in code sample.

Thanks grossmanandy at bfusa com and Simon Charette.

comment:6 Changed 3 years ago by Aymeric Augustin <aymeric.augustin@…>

In d90abcc9dad9b239e77aa67bfdd0c431072e2434:

[1.5.x] Fixed #19632 -- Bug in code sample.

Thanks grossmanandy at bfusa com and Simon Charette.

Backport of 1dd7492.

Note: See TracTickets for help on using tickets.
Back to Top