Skip to content
Browse files

Adding empty_items filter. Stupid little filter

lets you make a list of null objects.
  • Loading branch information...
1 parent 57c317f commit 3d2a05adcdcc49b81e4ca41b39f58a0ac7a1e59b @nathanborror committed Mar 18, 2011
Showing with 13 additions and 0 deletions.
  1. +13 −0 basic/tools/templatetags/listutils.py
View
13 basic/tools/templatetags/listutils.py
@@ -29,3 +29,16 @@ def pop_from_GET(obj, attr):
if not obj:
return ''
return '&%s' % obj.urlencode()
+
+
+@register.filter
+def empty_items(item_list, total):
+ """
+ Returns a list of null objects. Useful when you want to always show n
+ results and you have a list of < n.
+ """
+ list_length = len(item_list)
+ expected_total = int(total)
+ if list_length != expected_total:
+ return range(0, expected_total-list_length)
+ return ''

0 comments on commit 3d2a05a

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