@require_objs_permissions_for_view(
    perm_names=["can_remove_members"],
    permittee_func=get_user_from_req,
    target_func=get_queryset(Project, "proj_id"),
)
def remove_member(request, proj_id, user_id):
    """Kick a member out by stripping his roles"""
    
    project = get_object_or_404(Project, id=proj_id)
    member = get_object_or_404(User, id=user_id)

    if request.method == "POST":
        member = Permittee.objects.get_as_permittee(member)
        # Remove the roles
        for role in ProjectRole.objects.filter(project=project):
            role.remove_from_permittee(member)
        # Remove other permissions
        PermissionOwnership.objects.delete_all_for_target(project, member)

        #Remove can_use_aggregate if user is not member of any other project using the aggregates of this project
        for projectAgg in project._get_aggregates():
            aggNotUsedAnymoreByMember=1
            for p in Project.objects.exclude(id=project.id):
                if projectAgg in p._get_aggregates() and unicode(member) in p.members.values_list("username", flat=True):
                    aggNotUsedAnymoreByMember=0
                    break;
            if aggNotUsedAnymoreByMember and not has_permission(member, projectAgg, "can_use_aggregate"):
                projectAgg.remove_from_user(member,"/")

        try:
            #Sync LDAP
            project.save()
        except:
            logger.warning("User '%s' may have not been deleted from project '%s'. It could be a bug within LDAP." % (member.object.username, project.name))

        return HttpResponseRedirect(
            reverse("project_detail", args=[proj_id]))
    
    return simple.direct_to_template(
        request,
        template=TEMPLATE_PATH+"/remove_member.html",
        extra_context={
            "project": project,
            "member": member,
            "breadcrumbs": (
                ("Home", reverse("home")),
                ("Project %s" % project.name, reverse("project_detail", args=[project.id])),
                ("Remove Member %s" % member.username, request.path),
            ),
        },
    )
dataset/ETHPy150Open fp7-ofelia/ocf/expedient/src/python/expedient/clearinghouse/project/views.py/remove_member/original