Permalink
Browse files

Refactoring the get_vars filter into listutils.pop_from_GET and addin…

…g a remaining filter.
  • Loading branch information...
nathanborror committed Nov 8, 2010
1 parent 2272162 commit 665832444d7db38bc371ff7dcfe9dbe6c3a84bc1
Showing with 31 additions and 11 deletions.
  1. +0 −11 basic/tools/templatetags/comparison.py
  2. +31 −0 basic/tools/templatetags/listutils.py
@@ -43,14 +43,3 @@ def is_string(obj):
@register.filter
def is_number(obj):
return isinstance(obj, int)
-
-
-@register.filter
-def get_vars(obj):
- getvars = obj.copy()
- if 'page' in obj:
- del getvars['page']
- if len(getvars.keys()) > 0:
- return '&%s' % getvars.urlencode()
- else:
- return ''
@@ -0,0 +1,31 @@
+from django.template import Library
+
+register = Library()
+
+
+@register.filter
+def remaining(item_list, total):
+ """
+ Returns a null list of remaining items derived from the total. Usefull in
+ situations where you want exactly ten items in an interface and you may only
+ have eight items.
+ """
+ list_length = len(item_list)
+ expected_total = int(total)
+ if list_length != expected_total:
+ return range(0, expected_total-list_length)
+ return ''
+
+
+@register.filter
+def pop_from_GET(obj, attr):
+ """
+ Returns GET parameters sans specified attribute.
+ """
+ if obj.get(attr, None):
+ obj_copy = obj.copy()
+ del obj_copy[attr]
+ return '&%s' % obj_copy.urlencode()
+ if not obj:
+ return ''
+ return '&%s' % obj.urlencode()

0 comments on commit 6658324

Please sign in to comment.