'Return a list of all the visible groups the user is a member of or pending
membership. The groups pending membership will have a .pending attribute
set to True, others will have it set False.'

def get_annotated_groups(self):

    groups = []
    groups_manager = self.groups
    if hasattr(groups_manager, 'visible'):
        user_group_ids = list(groups_manager.visible().values_list('id', flat=True))
    else:
        user_group_ids = []
    for membership in self.groupmembership_set.filter(group_id__in=user_group_ids):
        group = membership.group
        group.pending = (membership.status == GroupMembership.PENDING)
        group.pending_terms = (membership.status == GroupMembership.PENDING_TERMS)
        groups.append(group)
    return groups
