1
# -*- coding: utf-8 -*-
2
from django import template
4
register = template.Library()
6
class SplitListNode(template.Node):
7
def __init__(self, list, cols, new_list):
10
self.new_list = new_list
12
def split_seq(self, list, cols=2):
14
for i in xrange(cols):
15
stop = start + len(list[i::cols])
16
yield list[start:stop]
19
def render(self, context):
20
context[self.new_list] = self.split_seq(context[self.list],
24
def list_to_columns(parser, token):
25
bits = token.contents.split()
27
raise template.TemplateSyntaxError, "list_to_columns list as new_list 2"
29
raise template.TemplateSyntaxError, "second argument to the list_to_columns tag must be 'as'"
30
return SplitListNode(bits[1], bits[4], bits[3])
31
list_to_columns = register.tag(list_to_columns)