X-Git-Url: https://git.stderr.nl/gitweb?a=blobdiff_plain;f=tools%2Ftemplatetags%2Flist.py;fp=tools%2Ftemplatetags%2Flist.py;h=e0111b00e4b03254915299a1844525a7cbead7d6;hb=78f556d0489510dc4b4cbcdb1980d2d2e7343b44;hp=0000000000000000000000000000000000000000;hpb=c2d741584e4bc6924ef74cd26db0ba9ec29ae130;p=matthijs%2Fprojects%2Fxerxes.git diff --git a/tools/templatetags/list.py b/tools/templatetags/list.py new file mode 100644 index 0000000..e0111b0 --- /dev/null +++ b/tools/templatetags/list.py @@ -0,0 +1,28 @@ +from django import template +from django.template.defaultfilters import unordered_list +from django.utils.safestring import mark_safe + +""" + Template tags and filters for working with lists. +""" + +register = template.Library() + +@register.filter(name='list_or_value') +def list_or_value(list, autoescape=None): + """ + Turn a list into a simple string or unordered list. + + If the list is empty, returns an empty string. + If the list contains one element, returns just that element. + If the list contains more elements, return an ordered list with + those elements (Just like the builtin unordered_list, but with the +