Skip to content

Instantly share code, notes, and snippets.

@garrypolley
Created September 21, 2012 15:06
Show Gist options
  • Select an option

  • Save garrypolley/3762045 to your computer and use it in GitHub Desktop.

Select an option

Save garrypolley/3762045 to your computer and use it in GitHub Desktop.

Revisions

  1. garrypolley created this gist Sep 21, 2012.
    10 changes: 10 additions & 0 deletions decorators.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,10 @@
    # -*- 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)
    11 changes: 11 additions & 0 deletions urls.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,11 @@
    # -*- 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')),
    )