Assume decorators, then, more or less:

def tagged(*tags):
        def decorate(view):
                @functools.wraps(view)
                def decorated(*args, **kw):
                        view(*args, **kw)
                decorated.tags = tags
                return decorated
        return decorate

(taking care to define a new function in the decorator so that you can use the 
same view with differnet tags in different URLs)

That doesn't seem too heavyweight to me. Am I missing something?

Assuming not, the decorator defined above can be used already with current 
production versions of Django for single URLs, and after the URL rework also 
on includes.

Your examples become

# Already today
api_v1_patterns = [
    url(r'^list/books/$', views.list_books, name='list-books'),
    url(r'^list/articles/$', tagged('public')(views.list_articles),
         name='list-articles'),
    ...
]

# After URL rework
urlpatterns = [
    url(r'^$', views.home, name='home'),
    url(r'^private/$', include(private_patterns), 
         decorators=[tagged('private')]),
    url(r'^api/1/', include(api_v1_patterns), decorators=[
        tagged('api', 'private', 'jsonp'),
    ]),
    url(r'^api/2/', include(api_v1_patterns), decorators=[
        tagged('api', 'cors', 'private'),
    ]),
]

 taking Marc's doubts (which I agree with) into account, and seeing as 1.9 is 
already feature-frozen, I think that the proper way forward for this feature 
is to live out of core.

If I am missing something, and it is hard to implement it out of core, please 
explain.

HTH,
        Shai.

Reply via email to