Add a remove_item template filter.
[matthijs/projects/xerxes.git] / tools / templatetags / misc.py
diff --git a/tools/templatetags/misc.py b/tools/templatetags/misc.py
new file mode 100644 (file)
index 0000000..2579295
--- /dev/null
@@ -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: