making an entry be available with its slug
[cascardo/ema.git] / urls.py
1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2008 Lincoln de Sousa <lincoln@minaslivre.org>
3 #
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License as
6 # published by the Free Software Foundation; either version 2 of the
7 # License, or (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 # General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public
15 # License along with this program; if not, write to the
16 # Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 # Boston, MA 02111-1307, USA.
18 from django.conf.urls.defaults import *
19 from django.conf import settings
20 from diario.settings import DIARIO_NUM_LATEST
21 from diario.models import Entry
22 from contents.models import Menu
23 from ema.views import get_entry_by_slug
24
25 MEDIA = {'document_root': settings.INSTANCE('media')}
26
27 # the only difference between info_dict and info_dict_full is that the
28 # full version contains all entries and the other has just entries
29 # without menus.
30
31 hasmenu = [x.entry.id for x in Menu.objects.all()]
32 info_dict = {
33     'queryset': Entry.published_on_site.exclude(id__in=hasmenu),
34     'template_object_name': 'entry',
35     'extra_context': {'menus': Menu.objects.all()},
36 }
37
38 info_dict_full = {
39     'queryset': Entry.published_on_site.all(),
40     'template_object_name': 'entry',
41     'extra_context': {'menus': Menu.objects.all()},
42 }
43
44 urlpatterns = patterns('',
45     (r'^admin/', include('django.contrib.admin.urls')),
46
47     url(regex='^$',
48         view='django.views.generic.list_detail.object_list',
49         kwargs=dict(info_dict, paginate_by=DIARIO_NUM_LATEST),
50         name='index'),
51
52     url(regex='^(?P<year>\d{4})/(?P<month>[0-9]{2})/(?P<day>\d{2})/(?P<slug>[-\w]+)/$',
53         view='diario.views.entries.entry_detail',
54         kwargs=dict(info_dict_full, slug_field='slug', month_format='%m',
55                     date_field='pub_date'),
56         name='diario-entry'),
57
58     (r'^([-\w]+)/$', get_entry_by_slug),
59     (r'^', include('ema.eventos.urls')),
60
61     # static media
62     (r'^(?P<path>imgs/.*)$', 'django.views.static.serve', MEDIA),
63     (r'^(?P<path>css/.*)$', 'django.views.static.serve', MEDIA),
64 )