def view_current_profile(request, contextArg): """this view displays account information and allows users to edit their information """ if request.user.is_anonymous(): #tell user they need to be logged in to do that return HttpResponseRedirect('/accounts/login/') #redirect to login page else: currentUser = request.user userProfile = profileUtil.getProfileFromUser(currentUser) print(userProfile.personalShed) reputation = profileUtil.getReputation(userProfile) timeCreated = userProfile.timeCreated streetAddress = profileUtil.getAddress(userProfile) city = profileUtil.getCity(userProfile) state = profileUtil.getStateName(userProfile) shareZone = profileUtil.getSharezone(userProfile) context = {} context.update(csrf(request)) context['userProfile'] = userProfile context['timeStamp'] = timeCreated context['streetAddress'] = streetAddress context['reputation'] = reputation context['city'] = city context['state'] = state context['sharezone'] = shareZone context.update(content.genBaseLoggedIn(request)) if contextArg: context.update(contextArg) return render_to_response('my_account.html', context)
def view_current_profile(request, contextArg): """this view displays account information and allows users to edit their information """ if request.user.is_anonymous(): #tell user they need to be logged in to do that return HttpResponseRedirect( '/accounts/login/') #redirect to login page else: currentUser = request.user userProfile = profileUtil.getProfileFromUser(currentUser) print(userProfile.personalShed) reputation = profileUtil.getReputation(userProfile) timeCreated = userProfile.timeCreated streetAddress = profileUtil.getAddress(userProfile) city = profileUtil.getCity(userProfile) state = profileUtil.getStateName(userProfile) shareZone = profileUtil.getSharezone(userProfile) context = {} context.update(csrf(request)) context['userProfile'] = userProfile context['timeStamp'] = timeCreated context['streetAddress'] = streetAddress context['reputation'] = reputation context['city'] = city context['state'] = state context['sharezone'] = shareZone context.update(content.genBaseLoggedIn(request)) if contextArg: context.update(contextArg) return render_to_response('my_account.html', context)
def test_UpdateReputation(self): rep = profUtils.getReputation(self.getProfile) profUtils.updateReputation(self.getProfile, 10) self.assertGreater (profUtils.getReputation(self.getProfile), rep) #make sure his reputation updates
def test_GetReputation(self): """ """ self.assertEqual (profUtils.getReputation(self.getProfile), 50) #change his name to Ben and then make sure it was saved
def test_UpdateReputation(self): rep = profUtils.getReputation(self.getProfile) profUtils.updateReputation(self.getProfile, 10) self.assertGreater(profUtils.getReputation(self.getProfile), rep) #make sure his reputation updates
def test_GetReputation(self): """ """ self.assertEqual( profUtils.getReputation(self.getProfile), 50) #change his name to Ben and then make sure it was saved
def view_tool_page(request, id, contextArg):#contextArg is a dict to be added to the content dict if request.user.is_anonymous(): #tell user they need to be logged in to that #add message flag that will display to user "you must be logged in to..." return HttpResponseRedirect('/accounts/login') #redirect to login page else: if id is not None: try: toolObj = toolUtil.getToolFromID(id) except ObjectDoesNotExist: context = {} context['object'] = 'tool' context.update(content.genBaseLoggedIn(request)) return render_to_response("dne.html", context) else: context = {} context['object'] = 'tool' context.update(content.genBaseLoggedIn(request)) return render_to_response("dne.html", context) owner = toolUtil.getToolOwner(toolObj) name = toolUtil.getToolName(toolObj) description = toolUtil.getToolDescription(toolObj) tags = toolUtil.getToolTags(toolObj) borrower = toolUtil.getToolBorrower(toolObj) condition = toolUtil.getToolConditionReadable(toolObj) available = toolUtil.isToolAvailable(toolObj) actions = actionUtil.getProfileAction(profileUtil.getProfileFromUser(request.user)) actionBorrowRequest = None actionReturnRequest = None requesterProfile = None for action in actions: if action.tool == toolObj: if action.currrentState == "userBorrowRequest" or action.currrentState == "acceptDecline": actionBorrowRequest = action if action.currrentState == "markedReturned" or action.currrentState == "confirmReturned": actionReturnRequest = action if actionBorrowRequest: pendingBorrowRequest = True requesterProfile = actionBorrowRequest.requester else: pendingBorrowRequest = False if actionReturnRequest: pendingReturnRequest = True else: pendingReturnRequest = False if profileUtil.getProfileFromUser(request.user) == owner: ownedByUser = True else: ownedByUser = False meetsMinRep = (profileUtil.getReputation(profileUtil.getProfileFromUser(request.user)) >= toolObj.minimumReputation) profileObj = (profileUtil.getProfileFromUser(request.user)) canBorrow = profileObj.canBorrow context = {} context.update(csrf(request)) context['tool'] = toolObj context['name'] = name #TODO change to toolName context['owner'] = owner context['description'] = description context['tags'] = tags context['currentProfile'] = profileObj context['borrower'] = borrower context['requester'] = requesterProfile context['condition'] = condition context['available'] = available context['ownedByUser'] = ownedByUser context['meetsMin'] = meetsMinRep context['pendingBorrowRequest'] = pendingBorrowRequest context['pendingReturnRequest'] = pendingReturnRequest context['canBorrow'] = canBorrow context.update(content.genBaseLoggedIn(request)) if contextArg: context.update(contextArg) return render_to_response('tool_page.html', context)
def view_tool_page( request, id, contextArg): #contextArg is a dict to be added to the content dict if request.user.is_anonymous(): #tell user they need to be logged in to that #add message flag that will display to user "you must be logged in to..." return HttpResponseRedirect('/accounts/login') #redirect to login page else: if id is not None: try: toolObj = toolUtil.getToolFromID(id) except ObjectDoesNotExist: context = {} context['object'] = 'tool' context.update(content.genBaseLoggedIn(request)) return render_to_response("dne.html", context) else: context = {} context['object'] = 'tool' context.update(content.genBaseLoggedIn(request)) return render_to_response("dne.html", context) owner = toolUtil.getToolOwner(toolObj) name = toolUtil.getToolName(toolObj) description = toolUtil.getToolDescription(toolObj) tags = toolUtil.getToolTags(toolObj) borrower = toolUtil.getToolBorrower(toolObj) condition = toolUtil.getToolConditionReadable(toolObj) available = toolUtil.isToolAvailable(toolObj) actions = actionUtil.getProfileAction( profileUtil.getProfileFromUser(request.user)) actionBorrowRequest = None actionReturnRequest = None requesterProfile = None for action in actions: if action.tool == toolObj: if action.currrentState == "userBorrowRequest" or action.currrentState == "acceptDecline": actionBorrowRequest = action if action.currrentState == "markedReturned" or action.currrentState == "confirmReturned": actionReturnRequest = action if actionBorrowRequest: pendingBorrowRequest = True requesterProfile = actionBorrowRequest.requester else: pendingBorrowRequest = False if actionReturnRequest: pendingReturnRequest = True else: pendingReturnRequest = False if profileUtil.getProfileFromUser(request.user) == owner: ownedByUser = True else: ownedByUser = False meetsMinRep = (profileUtil.getReputation( profileUtil.getProfileFromUser(request.user)) >= toolObj.minimumReputation) profileObj = (profileUtil.getProfileFromUser(request.user)) canBorrow = profileObj.canBorrow context = {} context.update(csrf(request)) context['tool'] = toolObj context['name'] = name #TODO change to toolName context['owner'] = owner context['description'] = description context['tags'] = tags context['currentProfile'] = profileObj context['borrower'] = borrower context['requester'] = requesterProfile context['condition'] = condition context['available'] = available context['ownedByUser'] = ownedByUser context['meetsMin'] = meetsMinRep context['pendingBorrowRequest'] = pendingBorrowRequest context['pendingReturnRequest'] = pendingReturnRequest context['canBorrow'] = canBorrow context.update(content.genBaseLoggedIn(request)) if contextArg: context.update(contextArg) return render_to_response('tool_page.html', context)