Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

file 63 lines (45 sloc) 1.778 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
from django.conf.urls.defaults import url, patterns, include
from django.conf import settings
from django.contrib import admin
from django.shortcuts import redirect

import jingo
import sphinxapi
from django_arecibo.tasks import post as arecibo_post

sphinxapi.TIMEOUT = getattr(settings, 'SPHINX_TIMEOUT', 1)


def _error_page(request, status):
    """Render error pages with jinja2."""
    return jingo.render(request, '%d.html' % status, status=status)


handler404 = lambda r: _error_page(r, 404)
handler_csrf = lambda r, reason: jingo.render(r, 'csrf_error.html')


def handler500(request):
    arecibo = getattr(settings, 'ARECIBO_SERVER_URL', '')

    if arecibo:
        arecibo_post(request, 500)

    return _error_page(request, 500)


admin.autodiscover()


def unchannel(request):
    url = request.META['PATH_INFO']
    url = url.replace('beta/', '', 1).replace('release/', '', 1)
    qs = request.META['QUERY_STRING']
    if qs:
        url += '?' + qs
    return redirect(url, permanent=True)

urlpatterns = patterns('',
    ('', include('feedback.urls')),
    ('', include('website_issues.urls')),
    ('', include('search.urls')),
    ('', include('themes.urls')),

    (r'^admin/', include('myadmin.urls')),

    url(r'^about/?$', jingo.render, {'template': 'about.html'},
        name='about'),
    (r'^robots\.txt$', jingo.render, {'template': 'robots.txt',
                                      'mimetype': 'text/plain'}),
    url('^(?:beta|release)/', unchannel),
)

if settings.DEBUG:
    # Remove leading and trailing slashes so the regex matches.
    media_url = settings.MEDIA_URL.strip('/')
    urlpatterns += patterns('',
        (r'^%s/(?P<path>.*)$' % media_url, 'django.views.static.serve',
         {'document_root': settings.MEDIA_ROOT}),
    )
Something went wrong with that request. Please try again.