Created
May 14, 2012 14:10
-
-
Save andrewschoen/2694206 to your computer and use it in GitHub Desktop.
Django middleware to create a 'page header' in django-cms navigation.
This file contains 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
from django import http | |
class NotAPageMiddleware(object): | |
""" | |
This middleware checks to see if the cms page is assigned to a specific template | |
and if so will redirect to the next published child page. Needs to be after the | |
cms page middleware. | |
""" | |
def process_response(self, request, response): | |
in_admin = request.path.split('/')[1] == "admin" | |
if hasattr(request, "current_page") and not in_admin: | |
page = request.current_page | |
if page: | |
if page.template == "not-a-page.html": | |
if page.children.filter(published=True).count() > 0: | |
child = page.children.filter(published=True)[0] | |
return http.HttpResponseRedirect(child.get_absolute_url()) | |
return response |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment