Code

Opened 18 months ago

Closed 18 months ago

Last modified 17 months 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 18 months ago.

Download all attachments as: .zip

Change History (7)

comment:1 Changed 18 months 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 18 months 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 18 months ago by charettes

  • Has patch set

Added the doc fix.

comment:4 Changed 18 months 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 18 months 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 17 months 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.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.