+
+@register.filter(name='natural_list')
+def natural_list(list):
+ """
+ Turns the list into a natural list, using comma's and "and" for
+ joining the terms. The result is somewhat localized (but probably
+ insufficient for language that use completely different
+ interpunction for lists).
+ """
+ if len(list) == 0:
+ return ''
+ res = ''
+ for item in list[0:-1]:
+ if res:
+ res += ', '
+ res += force_unicode(item)
+
+ if res:
+ res += ' %s ' % _('and')
+
+ res += force_unicode(list[-1])
+
+ return res
+natural_list.is_safe = True