Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Use proper views for the blog.

  • Loading branch information...
commit e42e8a112641104b872af3b7ed8ac81e5bb0455a 1 parent 0ea9363
Julien Phalip authored May 11, 2011
23  django_website/blog/urls.py
... ...
@@ -1,24 +1,13 @@
1 1
 from __future__ import absolute_import
2 2
 
3 3
 from django.conf.urls.defaults import *
4  
-from django.views.generic import date_based
5  
-
6  
-from .models import Entry
7  
-
8  
-
9  
-def prepare_arguments(view):
10  
-    def wrapped(request, *args, **kwargs):
11  
-        kwargs['allow_future'] = request.user.is_staff
12  
-        kwargs['queryset'] = Entry.objects.all() if request.user.is_staff else Entry.objects.published()
13  
-        kwargs['date_field'] = 'pub_date'
14  
-        return view(request, *args, **kwargs)
15  
-    return wrapped
16 4
 
  5
+from . import views
17 6
 
18 7
 urlpatterns = patterns('',
19  
-   (r'^(?P<year>\d{4})/(?P<month>[a-z]{3})/(?P<day>\w{1,2})/(?P<slug>[\w-]+)/$', prepare_arguments(date_based.object_detail)),
20  
-   (r'^(?P<year>\d{4})/(?P<month>[a-z]{3})/(?P<day>\w{1,2})/$', prepare_arguments(date_based.archive_day)),
21  
-   (r'^(?P<year>\d{4})/(?P<month>[a-z]{3})/$', prepare_arguments(date_based.archive_month)),
22  
-   (r'^(?P<year>\d{4})/$', prepare_arguments(date_based.archive_year)),
23  
-   url(r'^/?$', prepare_arguments(date_based.archive_index), name="blog-index"),
  8
+   (r'^(?P<year>\d{4})/(?P<month>[a-z]{3})/(?P<day>\w{1,2})/(?P<slug>[\w-]+)/$', views.entry_detail),
  9
+   (r'^(?P<year>\d{4})/(?P<month>[a-z]{3})/(?P<day>\w{1,2})/$', views.archive_day),
  10
+   (r'^(?P<year>\d{4})/(?P<month>[a-z]{3})/$', views.archive_month),
  11
+   (r'^(?P<year>\d{4})/$', views.archive_year),
  12
+   url(r'^/?$', views.archive_index, name="blog-index"),
24 13
 )
36  django_website/blog/views.py
... ...
@@ -0,0 +1,36 @@
  1
+from django.views.generic import date_based
  2
+
  3
+from .models import Entry
  4
+
  5
+def prepare_arguments(view):
  6
+    def wrapped(request, *args, **kwargs):
  7
+        kwargs['allow_future'] = request.user.is_staff
  8
+        kwargs['queryset'] = Entry.objects.all() if request.user.is_staff else Entry.objects.published()
  9
+        kwargs['date_field'] = 'pub_date'
  10
+        return view(request, *args, **kwargs)
  11
+    return wrapped
  12
+
  13
+@prepare_arguments
  14
+def entry_detail(request, *args, **kwargs):
  15
+    return date_based.object_detail(request, *args, **kwargs)
  16
+
  17
+@prepare_arguments
  18
+def archive_day(request, *args, **kwargs):
  19
+    return date_based.archive_day(request, *args, **kwargs)
  20
+
  21
+@prepare_arguments
  22
+def archive_month(request, *args, **kwargs):
  23
+    return date_based.archive_month(request, *args, **kwargs)
  24
+
  25
+@prepare_arguments
  26
+def archive_year(request, *args, **kwargs):
  27
+    return date_based.archive_year(request, *args, **kwargs)
  28
+
  29
+@prepare_arguments
  30
+def archive_index(request, *args, **kwargs):
  31
+    return date_based.archive_index(request, *args, **kwargs)
  32
+
  33
+
  34
+
  35
+
  36
+

0 notes on commit e42e8a1

Please sign in to comment.
Something went wrong with that request. Please try again.