From 06b512bb8370c00e2f5f28096ec0d6e7d591a989 Mon Sep 17 00:00:00 2001 From: Matthijs Kooijman Date: Fri, 16 Jan 2009 22:15:56 +0100 Subject: [PATCH] Add a remove_item template filter. The filter can be used to remove items from lists or dicts. --- tools/templatetags/misc.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 tools/templatetags/misc.py diff --git a/tools/templatetags/misc.py b/tools/templatetags/misc.py new file mode 100644 index 0000000..2579295 --- /dev/null +++ b/tools/templatetags/misc.py @@ -0,0 +1,20 @@ +from django import template + +""" + Miscellaneous template tags and filters. +""" + +register = template.Library() +@register.filter(name='remove_item') +def remove_item(container, item): + """ + Removes the given user from the filtered list or dict. + """ + if (item in container): + if isinstance(container, list): + container.remove(item) + elif isinstance(container, dict): + container.pop(item) + return container + +# vim: set sts=4 sw=4 expandtab: -- 2.30.2