Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Make sure only published entries are publicly accessible.

  • Loading branch information...
commit cb9d5e9f8747e963a202b90ec85dba5f6bd5303b 1 parent 48113e0
@jphalip jphalip authored
View
3  django_website/blog/models.py
@@ -10,6 +10,9 @@
class EntryManager(models.Manager):
+ def published(self):
+ return self.active().filter(pub_date__lte=datetime.datetime.now())
+
def active(self):
return super(EntryManager, self).get_query_set().filter(is_active=True)
View
7 django_website/blog/templatetags/weblog.py
@@ -1,6 +1,5 @@
from __future__ import absolute_import
-import datetime
from django import template
from ..models import Entry
@@ -8,7 +7,7 @@
@register.inclusion_tag('blog/entry_snippet.html')
def render_latest_blog_entries(num):
- entries = Entry.objects.filter(pub_date__lte=datetime.datetime.now())[:num]
+ entries = Entry.objects.published()[:num]
return {
'entries': entries,
}
@@ -16,5 +15,5 @@ def render_latest_blog_entries(num):
@register.inclusion_tag('blog/month_links_snippet.html')
def render_month_links():
return {
- 'dates': Entry.objects.dates('pub_date', 'month'),
- }
+ 'dates': Entry.objects.published().dates('pub_date', 'month'),
+ }
View
2  django_website/blog/urls.py
@@ -9,7 +9,7 @@
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.active()
+ 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
Please sign in to comment.
Something went wrong with that request. Please try again.