Add filtering to kaehmy list

This commit is contained in:
Jan Tuomi
2017-10-18 12:13:14 +03:00
parent cd94c0d0f4
commit b3aec2b3e4
7 changed files with 79 additions and 38 deletions
+12 -2
View File
@@ -1,5 +1,6 @@
"""Webapp views."""
from django.db.models import Count
from django.shortcuts import render, redirect
from django.contrib.auth import login, logout, authenticate
from django.views.decorators.http import require_http_methods
@@ -226,11 +227,20 @@ def ohlhafv_list(request, *args, **kwargs):
def kaehmy_list_view(request, *args, **kwargs):
"""Kaehmy application list"""
applications = KaehmyForm.objects.order_by('-timestamp')
role_filter = request.GET.get('role', None)
if role_filter is not None and str(role_filter) != '-1':
applications = KaehmyForm.objects.filter(custom_roles__id=role_filter) | KaehmyForm.objects.filter(preset_roles__id=role_filter)
else:
applications = KaehmyForm.objects.all()
applications = applications.order_by('-timestamp')
filter_options_preset = PresetKaehmyRole.objects.annotate(form_count=Count('forms')).filter(form_count__gt=0)
filter_options = [(r.id, r.name, r.form_count) for r in filter_options_preset]
context = {
'applications': applications,
'application_count': len(applications)
'application_count': len(applications),
'filter_options': filter_options
}
return render(request, 'kaehmy_list.html', context)