Commit 893ac676 authored by Luko van der Maas's avatar Luko van der Maas
Browse files

Merge branch '857-board-explicit-end-dates' into 'master'

Add explicit end date for members to board pages

Closes #857

See merge request !1325
parents ebd86892 bc2ada47
......@@ -277,11 +277,27 @@ class MemberGroupMembership(models.Model, metaclass=ModelTranslateMeta):
until__gte=self.since - datetime.timedelta(days=1))
if qs.count() >= 1: # should actually only be one; should be unique
if qs.count() >= 1: # should only be one; should be unique
return qs.first().initial_connected_membership
return self
def latest_connected_membership(self):
Find the newest membership directly connected to the current one
(thus the membership that started at the moment the current one ended)
if self.until:
qs = MemberGroupMembership.objects.filter(,
since__gte=self.until + datetime.timedelta(days=1))
if qs.count() >= 1: # should only be one; should be unique
return qs.last().latest_connected_membership
return self
def is_active(self):
"""Is this membership currently active"""
......@@ -29,18 +29,25 @@ def membergroup_card(group):
def membergroup_member_card(membership):
meta_text = ''
if 'since' in membership:
since_text = '{}: ?'.format(_('Member since'))
if membership['since'].year > 1970:
since_text = '{}: {}'.format(_('Member since'),
meta_text += '<p class="px-1">{}</p>'.format(since_text)
if 'role' in membership and membership['role']:
meta_text += '<p class="px-1">{}</p>'.format(membership['role'])
meta_text += f"<p class=\"px-1\">{membership['role']}</p>"
ribbon = None
if membership['chair']:
if membership['chair'] and not membership['until']:
ribbon = _('Chair')
if 'since' in membership and not membership['is_board']:
since_text = '{}: ?'.format(_('Member since'))
if membership['since'].year > 1970:
since_text = f"{_('Member since')}: {membership['since'].year}"
meta_text += f'<p class="px-1"><em>{since_text}</em></p>'
if ('until' in membership and membership['until']
and membership['is_board']):
until_text = f"{_('until')} {membership['until']}"
meta_text += f'<p class="px-1"><em>{until_text}</em></p>'
return member_card(
......@@ -16,18 +16,23 @@ class _MemberGroupDetailView(DetailView):
context_object_name = 'membergroup'
def _get_memberships(self, group):
return MemberGroupMembership.active_objects.filter(group=group)
def get_context_data(self, **kwargs) -> dict:
context = super().get_context_data(**kwargs)
memberships = (MemberGroupMembership
memberships = (self._get_memberships(context['membergroup'])
members = [{
'member': x.member,
'chair': x.chair,
'role': x.role,
'since': x.initial_connected_membership.since
'since': x.initial_connected_membership.since,
'until': (None if x.latest_connected_membership.until ==
context['membergroup'].until else
'is_board': hasattr(, 'board')
} for x in memberships]
members.sort(key=lambda x: x['since'])
......@@ -110,6 +115,9 @@ class BoardDetailView(_MemberGroupDetailView):
template_name = 'activemembers/board_detail.html'
context_object_name = 'membergroup'
def _get_memberships(self, group):
return MemberGroupMembership.objects.filter(group=group)
def get_object(self, queryset=None) -> Board:
return get_object_or_404(
Markdown is supported
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