Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Changed django_website get_latest_blog_entry templatetag to take a va…

…riable of number of entries to retrieve

git-svn-id: http://code.djangoproject.com/svn/djangoproject.com@47 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 5a339775cb2b6f82a7ccea67fcbe0f3e1826ac52 1 parent bafec3c
adrian authored
Showing with 11 additions and 15 deletions.
  1. +11 −15 django_website/apps/blog/templatetags/latestblogentry.py
View
26 django_website/apps/blog/templatetags/latestblogentry.py
@@ -1,27 +1,23 @@
from django.core import template
from django.models.blog import entries
-class LatestBlogEntryNode(template.Node):
- def __init__(self, varname):
- self.varname = varname
+class LatestBlogEntriesNode(template.Node):
+ def __init__(self, num, varname):
+ self.num, self.varname = num, varname
def render(self, context):
- try:
- e = entries.get_latest()
- except entries.EntryDoesNotExist:
- e = None
- context[self.varname] = e
+ context[self.varname] = entries.get_list(limit=self.num)
return ''
-def do_get_latest_blog_entry(parser, token):
+def do_get_latest_blog_entries(parser, token):
"""
- {% get_latest_blog_entry as latest_entry %}
+ {% get_latest_blog_entries 2 as latest_entries %}
"""
bits = token.contents.split()
- if len(bits) != 3:
- raise template.TemplateSyntaxError, "'%s' tag takes two arguments" % bits[0]
- if bits[1] != 'as':
+ if len(bits) != 4:
+ raise template.TemplateSyntaxError, "'%s' tag takes three arguments" % bits[0]
+ if bits[2] != 'as':
raise template.TemplateSyntaxError, "First argument to '%s' tag must be 'as'" % bits[0]
- return LatestBlogEntryNode(bits[2])
+ return LatestBlogEntryNode(bits[1], bits[3])
-template.register_tag('get_latest_blog_entry', do_get_latest_blog_entry)
+template.register_tag('get_latest_blog_entries', do_get_latest_blog_entries)
Please sign in to comment.
Something went wrong with that request. Please try again.