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

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):
member=self.member,
until__lte=self.since,
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
else:
return self
@property
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(
group=self.group,
member=self.member,
since__lte=self.until,
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
@property
def is_active(self):
"""Is this membership currently active"""
......
......@@ -29,18 +29,25 @@ def membergroup_card(group):
@register.inclusion_tag('includes/grid_item.html')
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'),
membership['since'].year)
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(
member=membership['member'],
meta_text=meta_text,
......
......@@ -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
.active_objects
.filter(group=context['membergroup'])
memberships = (self._get_memberships(context['membergroup'])
.prefetch_related('member__membergroupmembership_set'))
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
x.latest_connected_membership.until),
'is_board': hasattr(x.group, '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(
Board,
......
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