commit d895de3769de5438b836c766e957592dd2b94d8e
Author: Giorgos Korfiatis <gkorf@grnet.gr>
Date:   Thu Jun 27 17:10:47 2013 +0300

    astakos: Fix listing of approved members
    
    Include leave requested and suspended members in the list of approved.

diff --git a/snf-astakos-app/astakos/im/models.py b/snf-astakos-app/astakos/im/models.py
index 38dba4d..716ac02 100644
--- a/snf-astakos-app/astakos/im/models.py
+++ b/snf-astakos-app/astakos/im/models.py
@@ -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 = {
diff --git a/snf-astakos-app/astakos/im/tables.py b/snf-astakos-app/astakos/im/tables.py
index 45f61c3..7451d13 100644
--- a/snf-astakos-app/astakos/im/tables.py
+++ b/snf-astakos-app/astakos/im/tables.py
@@ -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?')]
diff --git a/snf-astakos-app/astakos/im/views/projects.py b/snf-astakos-app/astakos/im/views/projects.py
index 69ed79c..aafbc35 100644
--- a/snf-astakos-app/astakos/im/views/projects.py
+++ b/snf-astakos-app/astakos/im/views/projects.py
@@ -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,
