added 'tables' template tags to display objects lists in 'maraudes' and 'sujets'

This commit is contained in:
Arthur Gerbaud
2016-11-19 13:28:36 +01:00
parent 673c620be0
commit 7f08b1db23
11 changed files with 71 additions and 36 deletions

View File

@@ -0,0 +1,13 @@
<table class="table table-condensed">
{% for row in rows %}
<tr>
{% for object in row %}
<td>
{% if object %}
{% include cell_template with object=object %}
{%endif%}
</td>
{% endfor %}
</tr>
{% endfor %}
</table>

View File

@@ -0,0 +1 @@
{{ object }}

View File

@@ -0,0 +1,31 @@
from django import template
from itertools import zip_longest
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]
@register.inclusion_tag("tables/table.html")
def table(object_list, cols=2, cell_template="tables/table_cell.html"):
""" Render object list in table of given columns number """
return {
'cell_template': cell_template,
'rows': tuple(zip_longest( *get_columns(object_list, cols),
fillvalue=None
))
}
@register.inclusion_tag("tables/header_table.html")
def header_table(object_list, cols=2):
""" Display object list in table of given columns number """
return {
'cols': cols,
'rows': tuple(zip_longest( *get_columns(object_list, cols),
fillvalue=None
))
}

View File

@@ -31,5 +31,6 @@ def login_view(request):
if request.method == 'GET':
return HttpResponsePermanentRedirect('/')
elif request.method == 'POST':
#TODO: authenticate instead of mis-using 'login' view.
response = login(request)
return HttpResponseRedirect('/')