Opened 11 years ago
Closed 11 years ago
#22006 closed Cleanup/optimization (fixed)
DRY login_required method should be documented
Reported by: | Owned by: | mockforest | |
---|---|---|---|
Component: | Documentation | Version: | 1.6 |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | yes | UI/UX: | no |
Description
See https://code.djangoproject.com/ticket/16626 for the discussion.
Currently, the docs suggest decorating each class separately, they should also suggest the mixin as recommended in the ticket above, for setting login_required
(or others) on multiple classes.
Note: Creating a ProtectedView
superclass and subclassing doesn't work for the reason as specified in the Note
in the current docs:
https://docs.djangoproject.com/en/dev/topics/class-based-views/intro/#decorating-the-class
Attachments (3)
Change History (17)
comment:1 by , 11 years ago
Triage Stage: | Unreviewed → Accepted |
---|---|
Type: | Uncategorized → Cleanup/optimization |
comment:2 by , 11 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
by , 11 years ago
Attachment: | ticket-22006.diff added |
---|
comment:3 by , 11 years ago
Has patch: | set |
---|
comment:4 by , 11 years ago
Owner: | changed from | to
---|
comment:5 by , 11 years ago
Owner: | removed |
---|---|
Status: | assigned → new |
comment:7 by , 11 years ago
@chrismarceloph in your patch method as_view needs to be decorated with @classmethod
see https://code.djangoproject.com/ticket/16626 last comment
i would suggest to put that example into https://docs.djangoproject.com/en/dev/topics/class-based-views/intro/#using-mixins and then from https://docs.djangoproject.com/en/dev/topics/auth/default/#applying-permissions-to-generic-views refer to that example which is written in mixins sections instead of decorating dispatch
#nlsprint14
comment:8 by , 11 years ago
and if you are planning to finish this ticket, please register here and assign it to yourself
comment:9 by , 11 years ago
Owner: | set to |
---|---|
Status: | new → assigned |
@dzhibas: Thanks! I've registered and am planning to finish this ticket.
If I understand it correctly, you're suggesting I move the example to https://docs.djangoproject.com/en/dev/topics/class-based-views/intro/#using-mixins and refer to it from https://docs.djangoproject.com/en/dev/topics/auth/default/#applying-permissions-to-generic-views? Sounds good; I think that section needs an example too.
comment:10 by , 11 years ago
Patch needs improvement: | set |
---|
comment:11 by , 11 years ago
I think he just means to say you need to add @classmethod
on line 12 of your diff.
I'd probably also clarify the following;
- The mixin doesn't have to only be for
login_required
(maybe give another example asdjango.contrib.admin.views.decorators.staff_member_required
and also say you can create your own decorators) - Not sure if it's worth mentioning *why* creating a superclass, overriding
dispatch()
won't work (and hence why the mixin is better). See the note at https://docs.djangoproject.com/en/dev/topics/class-based-views/intro/#decorating-the-class
comment:12 by , 11 years ago
I didn't see the first line of @dzhibas's comment, sorry. Patch fixed.
And now I'm not so sure about the suggestions. I feel like the example belongs to three separate sections:
- Using mixins (https://docs.djangoproject.com/en/dev/topics/class-based-views/intro/#using-mixins),
- Decorating class-based views (https://docs.djangoproject.com/en/dev/topics/class-based-views/intro/#decorating-class-based-views), and
- Applying permissions to generic views (https://docs.djangoproject.com/en/dev/topics/auth/default/#applying-permissions-to-generic-views).
What would be the best way to do this?
comment:13 by , 11 years ago
Patch needs improvement: | unset |
---|
comment:14 by , 11 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
In 584044566414d3f4595337225aa23b52a089a680:
Fixed #22006 -- Documented how to write a login_required mixin for CBVs.
Thanks django at patjack.co.uk for the suggestion and mockforest
for the draft patch.
Submitted patch. (Sorry did not claim it first, first-timer here.)