Skip to content

Commit

Permalink
Merge pull request #96 from molgen/group-filter
Browse files Browse the repository at this point in the history
Group filter
  • Loading branch information
donald authored Sep 16, 2020
2 parents d546c44 + 2c11bf5 commit 8b16d3b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
6 changes: 5 additions & 1 deletion mpicms/personal/views.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from django.views.generic.list import ListView
from django.shortcuts import get_object_or_404

from .models import Contact, Group

Expand All @@ -15,7 +16,10 @@ 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 ""
return context


Expand Down
13 changes: 6 additions & 7 deletions mpicms/templates/personal/list.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,24 @@ <h1 class="title has-text-centered">{% trans 'Contact List' %}</h1>
<div class="dropdown">
<div class="dropdown-trigger">
<button class="button" aria-haspopup="true">
<span>{% trans 'Filter by group' %}</span>
<span>{% if selected_group %}{{selected_group}}{% else %}{% trans 'Filter by group' %} {% endif %}</span>
<span class="icon is-small">
<i class="fas fa-angle-down" aria-hidden="true"></i>
</span>
</button>
</div>
<div class="dropdown-menu" role="menu">
<hr class="dropdown-divider">
<a href="?" class="dropdown-item">
<em>{% trans 'Reset filter' %}</em>
</a>
<div class="dropdown-content">

{% for group in groups %}
<a href="?group={{ group.pk }}" class="{% if group.pk|stringformat:'d' == request.GET.group %}is-active {% endif %}dropdown-item">
<a href="?group={{ group.pk }}" class="{% if group.pk|stringformat:'d' == selected_group_pk %}is-active {% endif %}dropdown-item">
{{ group }}
</a>
{% endfor %}

<hr class="dropdown-divider">
<a href="?" class="dropdown-item">
{% trans 'Reset filter' %}
</a>
</div>
</div>
</div>
Expand Down

0 comments on commit 8b16d3b

Please sign in to comment.