added 'tables' template tags to display objects lists in 'maraudes' and 'sujets'
This commit is contained in:
13
website/templates/tables/table.html
Normal file
13
website/templates/tables/table.html
Normal 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>
|
||||
1
website/templates/tables/table_cell.html
Normal file
1
website/templates/tables/table_cell.html
Normal file
@@ -0,0 +1 @@
|
||||
{{ object }}
|
||||
31
website/templatetags/tables.py
Normal file
31
website/templatetags/tables.py
Normal 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
|
||||
))
|
||||
}
|
||||
@@ -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('/')
|
||||
|
||||
Reference in New Issue
Block a user