def projects(request): if request.method == 'POST': from project_actions import add_user_to_project, remove_user_from_project from project_actions import add_group_to_project, remove_group_from_project if request.POST['action'] == 'add': project_id = request.POST['project_id'] name = request.POST['name'] pa_project = PAProject.objects.get(id=project_id) try: pa_user = PAUser.objects.get(name=name) add_user_to_project(pa_project, pa_user) except: pa_group = PAGroup.objects.get(name=name) add_group_to_project(pa_project, pa_group) elif request.POST['action'] == 'remove_user': project_access_id = request.POST['user_with_access_id'] pa_project_access = PAUserProjectAccess.objects.get(id=project_access_id) remove_user_from_project(pa_project_access) elif request.POST['action'] == 'remove_group': project_access_id = request.POST['group_with_access_id'] pa_project_access = PAGroupProjectAccess.objects.get(id=project_access_id) remove_group_from_project(pa_project_access) else: raise Exception("Unsupported POST action") template = loader.get_template('projects.html') context = RequestContext(request, { 'projects': PAProject.objects.all(), }) return HttpResponse(template.render(context))
def destroy(self, request, project_pk, pk): project = self.get_project(project_pk) group_project_access = PAGroupProjectAccess.objects.get(id=pk) if PAGroupProjectAccess.objects.filter(project=project, id=group_project_access.pk).exists(): remove_group_from_project(group_project_access) return Response(None, status.HTTP_204_NO_CONTENT) else: return Response({u"detail": "Group is not part of project's access list"}, status.HTTP_404_NOT_FOUND)