From 6917782bec1b55affb358b18894dafb074386e08 Mon Sep 17 00:00:00 2001 From: Donald Buczek Date: Wed, 16 Sep 2020 14:57:06 +0200 Subject: [PATCH 1/2] personal: Make group filter more usable - Put "reset filter" on top of list - If a group is selected, show the name instead of "Filter by group" --- mpicms/personal/views.py | 4 ++++ mpicms/templates/personal/list.html | 13 ++++++------- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/mpicms/personal/views.py b/mpicms/personal/views.py index bcc49c6..207d043 100644 --- a/mpicms/personal/views.py +++ b/mpicms/personal/views.py @@ -1,4 +1,5 @@ from django.views.generic.list import ListView +from django.shortcuts import get_object_or_404 from .models import Contact, Group @@ -16,6 +17,9 @@ def get_queryset(self): def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) context['groups'] = Group.objects.all() + group_pk = self.request.GET.get('group') + context['selected_group_pk'] = group_pk + context['selected_group'] = get_object_or_404(Group, pk=group_pk) if group_pk else "" return context diff --git a/mpicms/templates/personal/list.html b/mpicms/templates/personal/list.html index e410f01..10afa74 100644 --- a/mpicms/templates/personal/list.html +++ b/mpicms/templates/personal/list.html @@ -8,25 +8,24 @@

{% trans 'Contact List' %}

From 2c11bf5e37794b1ae7c6562f020dd1aa9d48f537 Mon Sep 17 00:00:00 2001 From: Donald Buczek Date: Wed, 16 Sep 2020 14:59:56 +0200 Subject: [PATCH 2/2] personal: Sort groups by name in filter --- mpicms/personal/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mpicms/personal/views.py b/mpicms/personal/views.py index 207d043..740eeca 100644 --- a/mpicms/personal/views.py +++ b/mpicms/personal/views.py @@ -16,7 +16,7 @@ def get_queryset(self): def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) - context['groups'] = Group.objects.all() + context['groups'] = Group.objects.all().order_by("name") group_pk = self.request.GET.get('group') context['selected_group_pk'] = group_pk context['selected_group'] = get_object_or_404(Group, pk=group_pk) if group_pk else ""