def remove_shed_member(request, id, username): if request.user.is_anonymous(): return HttpResponseRedirect('/accounts/login') else: userProfile = profileUtil.getProfileFromUser(request.user) shedObj = shedUtil.getShedFromID(id) banUser = profileUtil.getProfileFromUser( User.objects.get(username=username)) admins = shedUtil.getAllAdminsOfShed(shedObj) userIsAdmin = False banUserIsAdmin = False for admin in admins: if admin == userProfile: userIsAdmin = True elif admin == banUser: banUserIsAdmin = True if userIsAdmin: if banUserIsAdmin: if shedObj.owner == userProfile: shedUtil.removeAdminFromShed(shedObj, banUser) notifUtil.createBadInfoNotif( shedObj, banUser, "You have been removed as an admin from the shed " + shedObj.name + ". ") shedUtil.removeMemberFromShed(shedObj, banUser) notifUtil.createBadInfoNotif( shedObj, banUser, "You have been kicked from the shed " + shedObj.name + ". ") shedTools = toolUtil.getAllToolsInShed(shedObj) for tool in shedTools: if tool.owner == banUser: shedUtil.removeToolFromShed(shedObj, tool) shedUtil.addToolToShed(banUser.personalShed, tool) return HttpResponseRedirect( "/sheds/" + str(shedObj.id) + "/remove_member/kicked/success") else: return HttpResponseRedirect('/') else: shedUtil.removeMemberFromShed(shedObj, banUser) shedObj.bannedUsers.add(banUser) notifUtil.createBadInfoNotif( shedObj, banUser, "You have been kicked from the shed " + shedObj.name + ". ") shedTools = toolUtil.getAllToolsInShed(shedObj) for tool in shedTools: if tool.owner == banUser: shedUtil.removeToolFromShed(shedObj, tool) shedUtil.addToolToShed(banUser.personalShed, tool) return HttpResponseRedirect("/sheds/" + str(shedObj.id) + "/remove_member/kicked/success") else: return HttpResponseRedirect('/')
def view_shed_page( request, id, contextArg): #contextArg is a dict to be added to the content dict if request.user.is_anonymous(): return HttpResponseRedirect("/accounts/login") else: if id is not None: try: shedObj = shedUtil.getShedFromID(id) except ObjectDoesNotExist: context = {} context['object'] = 'shed' context.update(content.genBaseLoggedIn(request)) return render_to_response("dne.html", context) else: context = {} context['object'] = 'shed' context.update(content.genBaseLoggedIn(request)) return render_to_response("dne.html", context) owner = shedUtil.getOwnerOfShed(shedObj) name = shedUtil.getNameOfShed(shedObj) admins = shedUtil.getAllAdminsOfShed(shedObj) isAdmin = False for admin in admins: if admin == profileUtil.getProfileFromUser(request.user): isAdmin = True members = shedUtil.getAllMembersOfShed(shedObj) tools = toolUtil.getAllToolsInShed(shedObj) userProfile = profileUtil.getProfileFromUser(request.user) meetsMinRep = userProfile.reputation >= shedObj.minimumReputation shedMembership = shedUtil.checkForMembership(userProfile, id) actions = actionUtil.getProfileAction( profileUtil.getProfileFromUser(request.user)) actionRequest = None pendingRequest = False for action in actions: if action.shed == shedObj: actionRequest = action if actionRequest: if actionRequest.currrentState == "userShedRequest" or actionRequest.currrentState == "acceptDeny": pendingRequest = True context = {} context.update(csrf(request)) context['shed'] = shedObj context['owner'] = owner context['currentUser'] = profileUtil.getProfileFromUser(request.user) context['name'] = name context['admins'] = admins context['members'] = members context['tools'] = tools context['meetsMin'] = meetsMinRep context['alreadyMember'] = shedMembership context['isAdmin'] = isAdmin context['pendingRequest'] = pendingRequest context.update(content.genBaseLoggedIn(request)) if contextArg: context.update(contextArg) return render_to_response('shed_page.html', context)
def view_shed_page(request, id, contextArg):#contextArg is a dict to be added to the content dict if request.user.is_anonymous(): return HttpResponseRedirect("/accounts/login") else: if id is not None: try: shedObj = shedUtil.getShedFromID(id) except ObjectDoesNotExist: context = {} context['object'] = 'shed' context.update(content.genBaseLoggedIn(request)) return render_to_response("dne.html", context) else: context = {} context['object'] = 'shed' context.update(content.genBaseLoggedIn(request)) return render_to_response("dne.html", context) owner = shedUtil.getOwnerOfShed(shedObj) name = shedUtil.getNameOfShed(shedObj) admins = shedUtil.getAllAdminsOfShed(shedObj) isAdmin = False for admin in admins: if admin == profileUtil.getProfileFromUser(request.user): isAdmin = True members = shedUtil.getAllMembersOfShed(shedObj) tools = toolUtil.getAllToolsInShed(shedObj) userProfile = profileUtil.getProfileFromUser(request.user) meetsMinRep = userProfile.reputation >= shedObj.minimumReputation shedMembership = shedUtil.checkForMembership(userProfile, id) actions = actionUtil.getProfileAction(profileUtil.getProfileFromUser(request.user)) actionRequest = None pendingRequest = False for action in actions: if action.shed == shedObj: actionRequest = action if actionRequest: if actionRequest.currrentState == "userShedRequest" or actionRequest.currrentState == "acceptDeny": pendingRequest = True context = {} context.update(csrf(request)) context['shed'] = shedObj context['owner'] = owner context['currentUser'] = profileUtil.getProfileFromUser(request.user) context['name'] = name context['admins'] = admins context['members'] = members context['tools'] = tools context['meetsMin'] = meetsMinRep context['alreadyMember'] = shedMembership context['isAdmin'] = isAdmin context['pendingRequest'] = pendingRequest context.update(content.genBaseLoggedIn(request)) if contextArg: context.update(contextArg) return render_to_response('shed_page.html', context)
def remove_shed_member(request, id, username): if request.user.is_anonymous(): return HttpResponseRedirect('/accounts/login') else: userProfile = profileUtil.getProfileFromUser(request.user) shedObj = shedUtil.getShedFromID(id) banUser = profileUtil.getProfileFromUser(User.objects.get(username=username)) admins = shedUtil.getAllAdminsOfShed(shedObj) userIsAdmin = False banUserIsAdmin = False for admin in admins: if admin == userProfile: userIsAdmin = True elif admin == banUser: banUserIsAdmin = True if userIsAdmin: if banUserIsAdmin: if shedObj.owner == userProfile: shedUtil.removeAdminFromShed(shedObj, banUser) notifUtil.createBadInfoNotif(shedObj, banUser, "You have been removed as an admin from the shed " + shedObj.name + ". ") shedUtil.removeMemberFromShed(shedObj, banUser) notifUtil.createBadInfoNotif(shedObj, banUser, "You have been kicked from the shed " + shedObj.name + ". ") shedTools = toolUtil.getAllToolsInShed(shedObj) for tool in shedTools: if tool.owner == banUser: shedUtil.removeToolFromShed(shedObj, tool) shedUtil.addToolToShed(banUser.personalShed, tool) return HttpResponseRedirect("/sheds/" + str(shedObj.id) + "/remove_member/kicked/success") else: return HttpResponseRedirect('/') else: shedUtil.removeMemberFromShed(shedObj, banUser) shedObj.bannedUsers.add(banUser) notifUtil.createBadInfoNotif(shedObj, banUser, "You have been kicked from the shed " + shedObj.name + ". ") shedTools = toolUtil.getAllToolsInShed(shedObj) for tool in shedTools: if tool.owner == banUser: shedUtil.removeToolFromShed(shedObj, tool) shedUtil.addToolToShed(banUser.personalShed, tool) return HttpResponseRedirect("/sheds/" + str(shedObj.id) + "/remove_member/kicked/success") else: return HttpResponseRedirect('/')
def leave_shed(request, id): if request.user.is_anonymous(): return HttpResponseRedirect('/accounts/login') else: userProfile = profileUtil.getProfileFromUser(request.user) shedObj = shedUtil.getShedFromID(id) if shedObj.owner == userProfile: return HttpResponseRedirect('/') else: admins = shedUtil.getAllAdminsOfShed(shedObj) for admin in admins: if admin == userProfile: shedUtil.removeAdminFromShed(shedObj, userProfile) shedUtil.removeMemberFromShed(shedObj, userProfile) shedTools = toolUtil.getAllToolsInShed(shedObj) for tool in shedTools: if tool.owner == userProfile: shedUtil.removeToolFromShed(shedObj, tool) shedUtil.addToolToShed(userProfile.personalShed, tool) return HttpResponseRedirect('/sheds/' + str(shedObj.id) + '/leave/success')
def test_GetAllToolsInShed(self): """ """ self.assertIn( self.ncTool, toolUtils.getAllToolsInShed(toolUtils.getToolShed(self.ncTool)))
def test_GetAllToolsInShed(self): """ """ self.assertIn (self.ncTool, toolUtils.getAllToolsInShed(toolUtils.getToolShed(self.ncTool)))