-
-
Save alanjds/31490c5b17412f366ea8c49dd4c0e7c4 to your computer and use it in GitHub Desktop.
Django decorate 3rd party app's views
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
from django.conf.urls import include | |
def decorated_include(urls, decorator) | |
"""Used to decorate all urls in a 3rd party app with a specific decorator""" | |
urls_to_decorate = include(urls) | |
for url_pattern in urls_to_decorate | |
url_pattern._callback = decorator(url_pattern._callback) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
from django.conf.urls import patterns, include, url | |
from django.contrib.auth.decorators import login_required | |
from .decorators import decorated_include | |
urlpatterns = patterns('', | |
url(r'^admin/', decorated_include('mongoanut.urls', login_required), | |
url(r'^auth/', include('social_auth.urls')), | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment