summaryrefslogtreecommitdiffstats
path: root/blog/urls.py
blob: 01cbfdd92a70a22eed0a9dfef0e5fa463c944e70 (plain)
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
from django.conf.urls.defaults import patterns
from django.db.models import Count
from blog.models import Post, PostCategory

date_info_dict = {
    'queryset': Post.objects.public(),
    'date_field': 'pub_date'
}
plain_info_dict = dict(date_info_dict, num_latest=10,
        template_name='blog/default.html')
year_info_dict = dict(date_info_dict, make_object_list=True)
month_info_dict = dict(date_info_dict, month_format='%m')
list_info_dict = {
    'queryset': Post.objects.public()
}
detail_info_dict = {
    'queryset': Post.objects.all(),
    'slug_field': 'slug'
}
category_info_dict = {
    'queryset': PostCategory.objects.filter(post__public=True).
            annotate(post_count=Count('post')).filter(post_count__gt=0)
}

# generic views
urlpatterns = patterns('django.views.generic.date_based',
    (r'^$',                                          'archive_index', plain_info_dict, "blog-index"),
    (r'^archive/(?P<year>\d{4})/$',                  'archive_year',  year_info_dict),
    (r'^archive/(?P<year>\d{4})/(?P<month>\d{2})/$', 'archive_month', month_info_dict),
)
urlpatterns += patterns('blog.views',
    # archive post index, grouped by year
    (r'^archive/$', 'archive_index', date_info_dict, "blog-archive"),
    # posts with a given category/tag
    (r'^tags/(?P<category>\w+)/$','postcategory_detail', category_info_dict, "blog-single-tag"),
)
urlpatterns += patterns('django.views.generic.list_detail',
    # category/tag list
    (r'^tags/$', 'object_list', category_info_dict, "blog-tags"),
    # individual post
    (r'^(?P<slug>[-\w]+)/$', 'object_detail', detail_info_dict, "blog-single-post"),
)

# vim: set ts=4 sw=4 et: