changes order in tables, fixes statistiques views navbar titles
This commit is contained in:
@@ -1,14 +1,15 @@
|
||||
from django import template
|
||||
from itertools import zip_longest
|
||||
from itertools import zip_longest, islice
|
||||
|
||||
register = template.Library()
|
||||
|
||||
def get_columns(iterable, cols):
|
||||
cols_len = len(iterable) // cols
|
||||
if len(iterable) % cols != 0:
|
||||
cols_len += 1
|
||||
for i in range(cols):
|
||||
yield iterable[i*cols_len:(i+1)*cols_len]
|
||||
def get_rows(iterable, cols):
|
||||
""" Returns a tuple of rows """
|
||||
i = iter(iterable)
|
||||
row = tuple(islice(i, cols))
|
||||
while row:
|
||||
yield row
|
||||
row = tuple(islice(i, cols))
|
||||
|
||||
@register.inclusion_tag("tables/table.html")
|
||||
def table(object_list, cols=2, cell_template="tables/table_cell_default.html", header=None):
|
||||
@@ -17,8 +18,6 @@ def table(object_list, cols=2, cell_template="tables/table_cell_default.html", h
|
||||
'cell_template': cell_template,
|
||||
'cols_number': cols,
|
||||
'header': header,
|
||||
'rows': tuple(zip_longest( *get_columns(object_list, cols),
|
||||
fillvalue=None
|
||||
))
|
||||
'rows': tuple(get_rows(object_list, cols)),
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user