Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Make sure only published entries are publicly accessible.

  • Loading branch information...
commit cb9d5e9f8747e963a202b90ec85dba5f6bd5303b 1 parent 48113e0
Julien Phalip authored May 10, 2011
3  django_website/blog/models.py
@@ -10,6 +10,9 @@
10 10
 
11 11
 class EntryManager(models.Manager):
12 12
     
  13
+    def published(self):
  14
+        return self.active().filter(pub_date__lte=datetime.datetime.now())
  15
+    
13 16
     def active(self):
14 17
         return super(EntryManager, self).get_query_set().filter(is_active=True)
15 18
 
7  django_website/blog/templatetags/weblog.py
... ...
@@ -1,6 +1,5 @@
1 1
 from __future__ import absolute_import
2 2
 
3  
-import datetime
4 3
 from django import template
5 4
 from ..models import Entry
6 5
 
@@ -8,7 +7,7 @@
8 7
 
9 8
 @register.inclusion_tag('blog/entry_snippet.html')
10 9
 def render_latest_blog_entries(num):
11  
-    entries = Entry.objects.filter(pub_date__lte=datetime.datetime.now())[:num]
  10
+    entries = Entry.objects.published()[:num]
12 11
     return {
13 12
         'entries': entries,
14 13
     }
@@ -16,5 +15,5 @@ def render_latest_blog_entries(num):
16 15
 @register.inclusion_tag('blog/month_links_snippet.html')
17 16
 def render_month_links():
18 17
     return {
19  
-        'dates': Entry.objects.dates('pub_date', 'month'),
20  
-    }
  18
+        'dates': Entry.objects.published().dates('pub_date', 'month'),
  19
+    }
2  django_website/blog/urls.py
@@ -9,7 +9,7 @@
9 9
 def prepare_arguments(view):
10 10
     def wrapped(request, *args, **kwargs):
11 11
         kwargs['allow_future'] = request.user.is_staff
12  
-        kwargs['queryset'] = Entry.objects.all() if request.user.is_staff else Entry.objects.active()
  12
+        kwargs['queryset'] = Entry.objects.all() if request.user.is_staff else Entry.objects.published()
13 13
         kwargs['date_field'] = 'pub_date'
14 14
         return view(request, *args, **kwargs)
15 15
     return wrapped

0 notes on commit cb9d5e9

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