urls.py 1.16 KB
Newer Older
Christophe Siraut's avatar
Christophe Siraut committed
1 2 3 4
from django.conf.urls import patterns, include, url
from django.views.generic import TemplateView
from django.views.generic import DetailView
from django.shortcuts import get_object_or_404
5 6
from flyers.content.models import Page
from flyers.general.models import Settings
Christophe Siraut's avatar
Christophe Siraut committed
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
from django.contrib import admin
admin.autodiscover()

class HomepageDetail(DetailView):
    model = Page
    def get_object(self):
        settings = Settings.objects.get(pk=1)
        if settings.home_page:
            return get_object_or_404(Page, pk=settings.home_page.pk)
        return None

urlpatterns = patterns('',
    # Examples:
    # url(r'^$', 'flyers.views.home', name='home'),
    # url(r'^blog/', include('blog.urls')),
    url(r'^admin/', include(admin.site.urls)),
    #url(r'^$', TemplateView.as_view(template_name='homepage.html')),
chris's avatar
chris committed
24
    (r'^i18n/', include('django.conf.urls.i18n')),
Christophe Siraut's avatar
Christophe Siraut committed
25 26 27 28 29 30 31 32 33 34 35
    url(r'^$', HomepageDetail.as_view()),
    url(r'^(?P<slug>.+)/$', DetailView.as_view(model=Page)),
)

import settings
if settings.DEBUG:
    urlpatterns += patterns('',
        url(r'^media/(?P<path>.*)$',
            'django.views.static.serve',
            {'document_root': settings.MEDIA_ROOT, }),
    )