Commit ae4625bc authored by Thom Wiggers's avatar Thom Wiggers 📐
Browse files

Merge branch 'feature/benefactors-tab' into 'master'

Add benefactors tab to members index

Closes #749

See merge request thalia/concrexit!1027
parents bf666595 f45758f8
......@@ -7,8 +7,8 @@ msgid ""
msgstr ""
"Project-Id-Version: \n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2018-10-25 20:13+0200\n"
"PO-Revision-Date: 2018-10-25 00:01+0200\n"
"POT-Creation-Date: 2018-10-31 00:27+0100\n"
"PO-Revision-Date: 2018-10-31 00:27+0100\n"
"Last-Translator: Thom Wiggers <thom@thomwiggers.nl>\n"
"Language-Team: \n"
"Language: nl\n"
......@@ -951,6 +951,10 @@ msgstr "Zoeken"
msgid "All members"
msgstr "Alle leden"
#: templates/members/index.html
msgid "Benefactors"
msgstr "Begunstigers"
#: templates/members/index.html
msgid "Honorary Members"
msgstr "Ere-leden"
......
......@@ -44,27 +44,35 @@
{% endfor %}
<li class="nav-item">
<a class="nav-link{% if filter == "old" %}active{% endif %}"
href="{% url 'members:index' %}?filter=old{% if keywords %}&keywords={{ keys }}{% endif %}{% if page %}&page={{ page }}{% endif %}#members-directory">
href="{% url 'members:index' %}?filter=older{% if keywords %}&keywords={{ keys }}{% endif %}{% if page %}&page={{ page }}{% endif %}#members-directory">
{% trans "Older" %}
</a>
</li>
<li class="nav-item">
<a class="nav-link{% if filter == "benefactors" %} active{% endif %}"
href="{% url 'members:index' %}?filter=benefactors{% if keywords %}&keywords={{ keys }}{% endif %}{% if page %}&page={{ page }}{% endif %}#members-directory">
{% trans "Benefactors" %}
</a>
</li>
<li class="nav-item">
<a class="nav-link{% if filter == "honor" %} active{% endif %}"
href="{% url 'members:index' %}?filter=honor{% if keywords %}&keywords={{ keys }}{% endif %}{% if page %}&page={{ page }}{% endif %}#members-directory">
href="{% url 'members:index' %}?filter=honorary{% if keywords %}&keywords={{ keys }}{% endif %}{% if page %}&page={{ page }}{% endif %}#members-directory">
{% trans "Honorary Members" %}
</a>
</li>
<li class="nav-item">
<a class="nav-link{% if filter == "ex" %} active{% endif %}"
href="{% url 'members:index' %}?filter=ex{% if keywords %}&keywords={{ keys }}{% endif %}{% if page %}&page={{ page }}{% endif %}#members-directory">
href="{% url 'members:index' %}?filter=former{% if keywords %}&keywords={{ keys }}{% endif %}{% if page %}&page={{ page }}{% endif %}#members-directory">
{% trans "Former Members" %}
</a>
</li>
</ul>
{% if not members %}
{% trans 'No members found' as info_text %}
{% alert 'info' info_text dismissable=True %}
<div class="mt-4">
{% trans 'No members found' as info_text %}
{% alert 'info' info_text dismissable=False %}
</div>
{% else %}
<div class="row mt-4">
{% for member in members %}
......
......@@ -181,14 +181,14 @@ class MembershipFilterTest(TestCase):
# user_id=6 has no memberships at all
def test_honorary(self):
members = filter_users('honor', '', [date.today().year])
members = filter_users('honorary', '', [date.today().year])
self.assertEqual(len(members), 1)
self.assertEqual(members[0].id, 0)
def test_ex(self):
members = filter_users('ex', '', [date.today().year])
def test_former(self):
members = filter_users('former', '', [date.today().year])
self.assertEqual(len(members), 3)
for member in members:
self.assertIn(member.id, {4, 5, 6})
# TODO more tests for other cases
# TODO more tests for other cases and move to services
......@@ -43,17 +43,22 @@ def filter_users(tab, keywords, year_range):
if tab and tab.isdigit():
members_query &= Q(profile__starting_year=int(tab))
elif tab == 'old':
memberships_query &= Q(type=Membership.MEMBER)
elif tab == 'older':
members_query &= Q(profile__starting_year__lt=year_range[-1])
elif tab == 'ex':
memberships_query &= Q(type=Membership.MEMBER)
elif tab == 'former':
# Filter out all current active memberships
memberships_query &= Q(type='member') | Q(type='honorary')
memberships_query &= (Q(type=Membership.MEMBER) |
Q(type=Membership.HONORARY))
memberships = models.Membership.objects.filter(memberships_query)
members_query &= ~Q(pk__in=memberships.values('user__pk'))
# Members_query contains users that are not currently (honorary)member
elif tab == 'honor':
elif tab == 'benefactors':
memberships_query &= Q(type=Membership.BENEFACTOR)
elif tab == 'honorary':
memberships_query = Q(until__gt=datetime.now().date()) | Q(until=None)
memberships_query &= Q(type='honorary')
memberships_query &= Q(type=Membership.HONORARY)
if keywords:
for key in keywords:
......@@ -65,8 +70,9 @@ def filter_users(tab, keywords, year_range):
Q(last_name__icontains=key) |
Q(username__icontains=key))
if tab == 'ex':
memberships_query = Q(type='member') | Q(type='honorary')
if tab == 'former':
memberships_query = (Q(type=Membership.MEMBER) |
Q(type=Membership.HONORARY))
memberships = models.Membership.objects.filter(memberships_query)
all_memberships = models.Membership.objects.all()
# Only keep members that were once members, or are legacy users that
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment