added 'tables' template tags to display objects lists in 'maraudes' and 'sujets'
This commit is contained in:
12
maraudes/templates/maraudes/list_table_cell.html
Normal file
12
maraudes/templates/maraudes/list_table_cell.html
Normal file
@@ -0,0 +1,12 @@
|
||||
{% if object.est_terminee %}
|
||||
<a href="{% url 'maraudes:details' object.id %}" class="btn btn-link">
|
||||
{% else %}
|
||||
<a href="#" class="btn btn-link disabled">
|
||||
{% endif %}
|
||||
{{object.date}}
|
||||
</a>
|
||||
<span class="label label-info">{{ object.binome }} & {{ object.referent }}</span>
|
||||
{% if object.est_terminee %}
|
||||
<span class="label label-success">{{object.rencontres.count}} rencontres</span>
|
||||
{% endif %}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
{% load bootstrap3 %}
|
||||
{% load tables %}
|
||||
<div class="col-md-12 col-lg-6">
|
||||
<div class="panel panel-primary">
|
||||
<!-- Default panel contents -->
|
||||
@@ -7,30 +8,7 @@
|
||||
</div>
|
||||
|
||||
<!-- Table -->
|
||||
<table class="table table-striped">
|
||||
{% for maraude in object_list %}
|
||||
<tr>
|
||||
<td>
|
||||
<div class="btn-group" role="group">
|
||||
{% if maraude.est_terminee %}
|
||||
<a href="{% url 'maraudes:details' maraude.id %}" class="btn btn-primary">
|
||||
{% elif perms.maraudes.can_add_compterendu %}
|
||||
<a href="{% url 'maraudes:create' maraude.id %}" class="btn btn-warning">
|
||||
{% else %}
|
||||
<a href="#" class="btn btn-default disabled">
|
||||
{% endif %}
|
||||
{{maraude.date}}
|
||||
{% if user.is_superuser %}
|
||||
</a><a class="btn btn-danger" href="/admin/maraudes/maraude/{{maraude.id}}/change/">{% bootstrap_icon "edit" %}
|
||||
{% endif %}</a></div>
|
||||
<div class="pull-right">
|
||||
<span class="label label-success">{{maraude.rencontres.count}} rencontres</span>
|
||||
<span class="label label-info">{{ maraude.binome }} & {{ maraude.referent }}</span>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</table>
|
||||
{% table object_list cols=2 cell_template="maraudes/list_table_cell.html" %}
|
||||
{% if is_paginated %}
|
||||
<div class="panel-footer text-center">
|
||||
<ul class="pagination">
|
||||
|
||||
@@ -115,7 +115,7 @@ class MaraudeListView(DerniereMaraudeMixin, generic.ListView):
|
||||
|
||||
model = CompteRendu
|
||||
template_name = "maraudes/liste.html"
|
||||
paginate_by = 10
|
||||
paginate_by = 30
|
||||
|
||||
class PageInfo:
|
||||
title = "Maraude - Liste des maraudes"
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
from notes.models import Note
|
||||
|
||||
from django import template
|
||||
|
||||
register = template.Library()
|
||||
|
||||
6
sujets/templates/sujets/list_table_cell.html
Normal file
6
sujets/templates/sujets/list_table_cell.html
Normal file
@@ -0,0 +1,6 @@
|
||||
<a href="{% url 'suivi:details' object.pk %}" class="btn btn-link">{{object}}</a>
|
||||
<div class="pull-right" style="padding-right: 20px;">
|
||||
<span class="label label-info">{{ object.notes.count }} notes</span>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
{% load tables %}
|
||||
{% load bootstrap3 %}
|
||||
<div class="col-md-12 col-lg-6">
|
||||
<div class="panel panel-primary">
|
||||
@@ -28,14 +29,7 @@
|
||||
</div>
|
||||
{% if object_list %}
|
||||
<!-- Table -->
|
||||
<table class="table table-striped table-hover">
|
||||
{% for sujet in object_list %}
|
||||
<tr>
|
||||
<td><a href="{% url 'suivi:details' sujet.pk %}" class="btn btn-link">{{sujet}}</a></td>
|
||||
<td><span class="label label-info">{{ sujet.notes.count }} notes</span></td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</table>
|
||||
{% table object_list cols=3 cell_template="sujets/list_table_cell.html" %}
|
||||
{% if is_paginated %}
|
||||
<div class="panel-footer text-center">
|
||||
<ul class="pagination">
|
||||
@@ -47,6 +41,7 @@
|
||||
{% endif %}{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-lg-3 col-md-3">
|
||||
<div class="panel panel-default">
|
||||
<!-- Default panel contents -->
|
||||
|
||||
@@ -35,7 +35,7 @@ class SujetListView(generic.ListView):
|
||||
#ListView
|
||||
model = Sujet
|
||||
template_name = "sujets/sujet_liste.html"
|
||||
paginate_by = 10
|
||||
paginate_by = 30
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
self.insert_menu("suivi/menu_sujets.html")
|
||||
|
||||
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