Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Use proper views for the blog.

  • Loading branch information...
commit e42e8a112641104b872af3b7ed8ac81e5bb0455a 1 parent 0ea9363
@jphalip jphalip authored
Showing with 42 additions and 17 deletions.
  1. +6 −17 django_website/blog/urls.py
  2. +36 −0 django_website/blog/views.py
View
23 django_website/blog/urls.py
@@ -1,24 +1,13 @@
from __future__ import absolute_import
from django.conf.urls.defaults import *
-from django.views.generic import date_based
-
-from .models import Entry
-
-
-def prepare_arguments(view):
- def wrapped(request, *args, **kwargs):
- kwargs['allow_future'] = request.user.is_staff
- kwargs['queryset'] = Entry.objects.all() if request.user.is_staff else Entry.objects.published()
- kwargs['date_field'] = 'pub_date'
- return view(request, *args, **kwargs)
- return wrapped
+from . import views
urlpatterns = patterns('',
- (r'^(?P<year>\d{4})/(?P<month>[a-z]{3})/(?P<day>\w{1,2})/(?P<slug>[\w-]+)/$', prepare_arguments(date_based.object_detail)),
- (r'^(?P<year>\d{4})/(?P<month>[a-z]{3})/(?P<day>\w{1,2})/$', prepare_arguments(date_based.archive_day)),
- (r'^(?P<year>\d{4})/(?P<month>[a-z]{3})/$', prepare_arguments(date_based.archive_month)),
- (r'^(?P<year>\d{4})/$', prepare_arguments(date_based.archive_year)),
- url(r'^/?$', prepare_arguments(date_based.archive_index), name="blog-index"),
+ (r'^(?P<year>\d{4})/(?P<month>[a-z]{3})/(?P<day>\w{1,2})/(?P<slug>[\w-]+)/$', views.entry_detail),
+ (r'^(?P<year>\d{4})/(?P<month>[a-z]{3})/(?P<day>\w{1,2})/$', views.archive_day),
+ (r'^(?P<year>\d{4})/(?P<month>[a-z]{3})/$', views.archive_month),
+ (r'^(?P<year>\d{4})/$', views.archive_year),
+ url(r'^/?$', views.archive_index, name="blog-index"),
)
View
36 django_website/blog/views.py
@@ -0,0 +1,36 @@
+from django.views.generic import date_based
+
+from .models import Entry
+
+def prepare_arguments(view):
+ def wrapped(request, *args, **kwargs):
+ kwargs['allow_future'] = request.user.is_staff
+ kwargs['queryset'] = Entry.objects.all() if request.user.is_staff else Entry.objects.published()
+ kwargs['date_field'] = 'pub_date'
+ return view(request, *args, **kwargs)
+ return wrapped
+
+@prepare_arguments
+def entry_detail(request, *args, **kwargs):
+ return date_based.object_detail(request, *args, **kwargs)
+
+@prepare_arguments
+def archive_day(request, *args, **kwargs):
+ return date_based.archive_day(request, *args, **kwargs)
+
+@prepare_arguments
+def archive_month(request, *args, **kwargs):
+ return date_based.archive_month(request, *args, **kwargs)
+
+@prepare_arguments
+def archive_year(request, *args, **kwargs):
+ return date_based.archive_year(request, *args, **kwargs)
+
+@prepare_arguments
+def archive_index(request, *args, **kwargs):
+ return date_based.archive_index(request, *args, **kwargs)
+
+
+
+
+
Please sign in to comment.
Something went wrong with that request. Please try again.