Source

Ochs / news / urls.py

Full commit
from django.conf.urls.defaults import *
from django.conf import settings
from django.http import Http404

from cms.views import details

from news.models import Story
from news.views import story_view

def page_dispatcher(request, slug):
    # CACHE ME OR YOU WILL GO TO HELL AND ANSWER FOR YOUR CRIMES
    slug_parts = [x for x in slug.split('/') if x]
    story_slug = slug_parts.pop()
    page_slug = '/'.join(slug_parts)
    try:
        story = Story.objects.get(slug=story_slug)
        if not page_slug in story.section.get_path():
            raise Http404
        return story_view(request, story)
    except Story.DoesNotExist:
        return details(request, slug=slug)

urlpatterns = (
    url(r'^$', details, {'slug':''}, name='pages-root'),
    url(r'^(?P<slug>[0-9A-Za-z-_.//]+)/$', page_dispatcher, name='pages-details-by-slug')
)

if settings.CMS_APPLICATIONS_URLS:
    from cms.appresolver import dynamic_app_regex_url_resolver
    urlpatterns = (dynamic_app_regex_url_resolver,) + urlpatterns

urlpatterns = patterns('', *urlpatterns)