Opened 18 years ago

Closed 18 years ago

#2357 closed enhancement (wontfix)

URL Patterns to have login_required or equiv to force authentication on any of the url's in that pattern

Reported by: root.lastnode@… Owned by: Adrian Holovaty
Component: Core (Other) Version:
Severity: normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

I found that protecting views from unauthorized access can become cumbersom when your building lots of protected pages.

Decorating a view with login_required to force authentication works perfectly, but is not DRY when decorating every view in an app.

In combination with generic views, there are a few problems here and there with generics that are not accepting login_required. (see ticket #1071)

If the url patterns had a way to set login_required on the entire list of expressions, one could protect an entire part of the site
with one simple statement. Mixing protected/unprotected patterns would still allow flexibility designing urlpatterns.

example:

from django.conf.urls.defaults import *

urlpatterns = patterns('myproject.myapp.views',
    (r'^$', 'index'),
)

urlpatterns += auth_patterns('', some_options?,
    (r'^list_protected/$', 'django.views.generic.list_detail.object_list', dict(mydict)),
    (r'^add_protected/$', 'django.views.generic.create_update.create_object', dict(mydict)),
    (r'^update_protected/$', 'django.views.generic.create_update.update_object', dict(mydict)),
    (r'^delete_protected/$', 'django.views.generic.create_update.delete_object', dict(mydict)),
)

Change History (2)

comment:1 by anonymous, 18 years ago

Summary: URL Patterns set have login_required or equiv to force authentication on any of the url's in that patternURL Patterns to have login_required or equiv to force authentication on any of the url's in that pattern

comment:2 by Adrian Holovaty, 18 years ago

Resolution: wontfix
Status: newclosed

I'm marking this as a wontfix now, because as of [3554], URLconfs can take any callable. That means you can pass login_required(my_generic_view) directly to the URLconf.

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