Split board and non-board applications to 2 tables

This commit is contained in:
Jan Tuomi
2017-10-30 14:43:16 +02:00
parent 2285bf02a9
commit 2501d034db
7 changed files with 59 additions and 31 deletions
+4 -6
View File
@@ -1,5 +1,7 @@
import django_tables2 as tables
from django.db.models import Count, Q
from django.utils.translation import ugettext as _
from webapp.models import OhlhafvChallenge, KaehmyForm
@@ -11,10 +13,6 @@ class OhlhafvTable(tables.Table):
class KaehmyExportTable(tables.Table):
class Meta:
model = KaehmyForm
exclude = ['text', 'messageparent_ptr', 'custom_role_name', 'custom_role_is_board']
exclude = ['text', 'messageparent_ptr', 'custom_role_name', 'custom_role_is_board', 'timestamp']
all_roles = tables.Column(verbose_name=_('Roles'))
has_any_board_role = tables.BooleanColumn(verbose_name=_('Applied for board'))
def __init__(self, *args, **kwargs):
super(KaehmyExportTable, self).__init__(*args, **kwargs)
all_roles = tables.Column(verbose_name=_('Roles'), orderable=False)
+10 -1
View File
@@ -9,7 +9,16 @@
<h2 style="padding-top: 1rem">{% trans "All applications" %}</h2>
</div>
{{ table|safe }}
<div>
<h4>{% trans "Board applications" %}</h4>
{{ board_table|safe }}
</div>
<div>
<h4>{% trans "Non-board applications" %}</h4>
{{ non_board_table|safe }}
</div>
<div>
<a href="/kaehmy" class="btn btn-primary">{% trans "Front page" %}</a>
</div>
+14 -8
View File
@@ -319,16 +319,22 @@ def kaehmy_submit(request, *args, **kwargs):
@require_http_methods(['GET'])
def kaehmy_export_view(request, *args, **kwargs):
def make_table(queryset):
table = KaehmyExportTable(queryset,
request=request,
exclude=['id'],
attrs={'class': 'table table-bordered table-hover'})
table.paginate(page=request.GET.get('page', 1), per_page=9999)
table_html = convert_table_to_html(table, request)
return table_html
kaehmys = KaehmyForm.objects.all()
non_board = filter(lambda q: not q.has_any_board_role(), kaehmys)
board = filter(lambda q: q.has_any_board_role(), kaehmys)
table = KaehmyExportTable(kaehmys,
request=request,
exclude=['id'],
attrs={'class': 'table table-bordered table-hover'})
table.paginate(page=request.GET.get('page', 1), per_page=9999)
table_html = convert_table_to_html(table, request)
context = {
'table': table_html,
'non_board_table': make_table(non_board),
'board_table': make_table(board),
}
return render(request, 'kaehmy_export.html', context)