8db2b3fbabc9ca0a448d685b022b66af03b8a394
[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, Index
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 inindex = [x.entry.id for x in Index.objects.all()]
33
34 info_dict = {
35     'queryset': Entry.published_on_site.exclude(id__in=hasmenu).filter(id__in=inindex),
36     'template_object_name': 'entry',
37     'extra_context': {'menus': Menu.objects.all()},
38 }
39
40 info_dict_full = {
41     'queryset': Entry.published_on_site.all(),
42     'template_object_name': 'entry',
43     'extra_context': {'menus': Menu.objects.all()},
44 }
45
46 urlpatterns = patterns('',
47     (r'^admin/', include('django.contrib.admin.urls')),
48
49     url(regex='^$',
50         view='django.views.generic.list_detail.object_list',
51         kwargs=dict(info_dict, paginate_by=DIARIO_NUM_LATEST),
52         name='index'),
53
54     url(regex='^(?P<year>\d{4})/(?P<month>[0-9]{2})/(?P<day>\d{2})/(?P<slug>[-\w]+)/$',
55         view='diario.views.entries.entry_detail',
56         kwargs=dict(info_dict_full, slug_field='slug', month_format='%m',
57                     date_field='pub_date'),
58         name='diario-entry'),
59
60     (r'^', include('ema.eventos.urls')),
61     (r'^([-\w]+)/$', get_entry_by_slug),
62
63     # static media
64     (r'^(?P<path>imgs/.*)$', 'django.views.static.serve', MEDIA),
65     (r'^(?P<path>css/.*)$', 'django.views.static.serve', MEDIA),
66 )