Commit 1309c393 authored by Giorgos Korfiatis's avatar Giorgos Korfiatis
Browse files

astakos: Fix listing of approved members

Include leave requested and suspended members in the list of approved.
parent 786329eb
......@@ -1906,15 +1906,7 @@ class Project(models.Model):
### Other
def count_pending_memberships(self):
memb_set = self.projectmembership_set
memb_count = memb_set.filter(state=ProjectMembership.REQUESTED).count()
return memb_count
def count_actually_accepted_memberships(self):
memb_set = self.projectmembership_set
memb_count = memb_set.filter(state=ProjectMembership.LEAVE_REQUESTED)
memb_count = memb_set.filter(state=ProjectMembership.ACCEPTED).count()
return memb_count
return self.projectmembership_set.requested().count()
def members_count(self):
return self.approved_memberships.count()
......@@ -1958,7 +1950,7 @@ CHAIN_STATE = {
class ProjectMembershipManager(ForUpdateManager):
def any_accepted(self):
q = self.model.Q_ACTUALLY_ACCEPTED
q = self.model.Q_ACCEPTED_STATES
return self.filter(q)
def actually_accepted(self):
......@@ -2006,7 +1998,7 @@ class ProjectMembership(models.Model):
objects = ProjectMembershipManager()
# Compiled queries
Q_ACCEPTED_STATES = ~Q(state=REQUESTED) & ~Q(state=REMOVED)
Q_ACCEPTED_STATES = Q(state__in=ACCEPTED_STATES)
Q_ACTUALLY_ACCEPTED = Q(state=ACCEPTED) | Q(state=LEAVE_REQUESTED)
MEMBERSHIP_STATE_DISPLAY = {
......
......@@ -344,7 +344,7 @@ def member_action_extra_context(membership, table, col):
_('Are you sure you want to accept this member?')]
confirms = [True, True]
if membership.state in ProjectMembership.ACTUALLY_ACCEPTED:
if membership.state in ProjectMembership.ACCEPTED_STATES:
urls = ['astakos.im.views.project_remove_member']
actions = [_('Remove')]
prompts = [_('Are you sure you want to remove this member?')]
......
......@@ -275,6 +275,12 @@ def addmembers(request, chain_id, addmembers_form):
messages.error(request, e)
MEMBERSHIP_STATUS_FILTER = {
0: lambda x: x.requested(),
1: lambda x: x.any_accepted(),
}
def common_detail(request, chain_or_app_id, project_view=True,
template_name='im/projects/project_detail.html',
members_status_filter=None):
......@@ -302,13 +308,13 @@ def common_detail(request, chain_or_app_id, project_view=True,
remaining_memberships_count = 0
project, application = get_by_chain_or_404(chain_id)
if project:
members = project.projectmembership_set.select_related()
approved_members_count = \
project.count_actually_accepted_memberships()
members = project.projectmembership_set
approved_members_count = project.members_count()
pending_members_count = project.count_pending_memberships()
if members_status_filter in (ProjectMembership.REQUESTED,
ProjectMembership.ACCEPTED):
members = members.filter(state=members_status_filter)
flt = MEMBERSHIP_STATUS_FILTER.get(members_status_filter)
if flt is not None:
members = flt(members)
members = members.select_related()
members_table = tables.ProjectMembersTable(project,
members,
user=request.user,
......
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