Ejemplo n.º 1
0
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)
Ejemplo n.º 2
0
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)
Ejemplo n.º 3
0
	def test_getProfileAction (self):
		self.assertTrue ((self.genBorrowReq in actUtils.getProfileAction(profUtils.getProfileFromUsername ("TaikhoomAttar")))\
		 and (self.genJoinReq in actUtils.getProfileAction(profUtils.getProfileFromUsername ("TaikhoomAttar"))))
Ejemplo n.º 4
0
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)
Ejemplo n.º 5
0
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)
Ejemplo n.º 6
0
 def test_getProfileAction(self):
     self.assertTrue ((self.genBorrowReq in actUtils.getProfileAction(profUtils.getProfileFromUsername ("TaikhoomAttar")))\
      and (self.genJoinReq in actUtils.getProfileAction(profUtils.getProfileFromUsername ("TaikhoomAttar"))))