Example #1
0
def user_register(request):
    if request.user.is_anonymous():
        if request.method == 'POST':
            form = UserRegistrationForm(request.POST)
            if form.is_valid():
                userAccount = form.save()
                user = authenticate(username=form.cleaned_data['username'], password=form.cleaned_data['password1'])
                if user is not None:
                    login(request, user)
                #send confirmation email
                sendMail(profileUtil.getProfileFromUser(userAccount), \
                    "Welcome aboard! ", "Thank you for registering with ToolCloud.")
                shedName = form.cleaned_data['username'] + "'s Shed"
                userProfile = profileUtil.getProfileFromUser(userAccount)
                newShedObject = Shed(name=shedName, owner=userProfile, location='location', sharezone=form.cleaned_data['zip_code'],\
                    status='status')
                newShedObject.save()
                newShedObject.members.add(userProfile)
                newShedObject.admins.add(userProfile)
                newShedObject.save()
                userProfile.personalShed = newShedObject
                context = {}
                context.update(content.genUserHome(request))
                context.update(content.addGoodRegisterNoti(dict()))
                return render_to_response('userHome.html', context)
        else:
            form = UserRegistrationForm()
        context = {}
        context.update(csrf(request))
        context['form'] = form
        context.update(content.genSuper())
        #Pass the context to a template
        return render_to_response('register.html', context)
    else:
        return HttpResponseRedirect('/')
Example #2
0
def create_tool_shed(request):
    if request.user.is_anonymous():
        #tell user they need to be logged in to do 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 request.method == 'POST':
            form = ShedCreationForm(request.user, request.POST)
            
            if form.is_valid():
                shed = form.save()
                profileObj = profileUtil.getProfileFromUser(request.user)
                shed.members.add(profileObj)
                shed.admins.add(profileObj)
                #send email
                sendMail(profileUtil.getProfileFromUser(request.user), \
                    "Your shed has been created! ", \
                    "Thanks for creating " + shed.name + \
                    " on ToolCloud.  We'll let you know when someone wants to join.")
                return HttpResponseRedirect('/sheds/' + str(shed.id) + '/success')
        else:
            form = ShedCreationForm(request.user)
        context = {}
        context.update(csrf(request))
        context['form'] = form
        context.update(content.genBaseLoggedIn(request))
        return render_to_response('shed_creation.html', context)
Example #3
0
def view_profile(request, username=None):
    if request.user.is_anonymous():
        #tell user they need to be logged in to do 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 username is not None:
            try:
                userProfile = profileUtil.getProfileFromUser(
                    User.objects.get(username=username))
            except ObjectDoesNotExist:
                context = {}
                context['object'] = 'profile'
                context.update(content.genBaseLoggedIn(request))
                return render_to_response("dne.html", context)
        else:
            userProfile = profileUtil.getProfileFromUser(request.user)
        toolsOwned = toolUtil.getAllToolsOwnedBy(userProfile)
        toolsBorrowed = toolUtil.getAllToolsBorrowedBy(userProfile)
        sheds = shedUtil.getAllShedsJoinedBy(userProfile)
        context = {}
        context.update(csrf(request))
        context['currentUser'] = request.user
        context['userProfile'] = userProfile
        context['toolsOwned'] = toolsOwned
        context['toolsBorrowed'] = toolsBorrowed
        context['sheds'] = sheds
        context.update(content.genBaseLoggedIn(request))
        return render_to_response('view_profile.html', context)
Example #4
0
def create_tool_shed(request):
    if request.user.is_anonymous():
        #tell user they need to be logged in to do 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 request.method == 'POST':
            form = ShedCreationForm(request.user, request.POST)

            if form.is_valid():
                shed = form.save()
                profileObj = profileUtil.getProfileFromUser(request.user)
                shed.members.add(profileObj)
                shed.admins.add(profileObj)
                #send email
                sendMail(profileUtil.getProfileFromUser(request.user), \
                    "Your shed has been created! ", \
                    "Thanks for creating " + shed.name + \
                    " on ToolCloud.  We'll let you know when someone wants to join.")
                return HttpResponseRedirect('/sheds/' + str(shed.id) +
                                            '/success')
        else:
            form = ShedCreationForm(request.user)
        context = {}
        context.update(csrf(request))
        context['form'] = form
        context.update(content.genBaseLoggedIn(request))
        return render_to_response('shed_creation.html', context)
Example #5
0
def view_profile(request, username=None):
    if request.user.is_anonymous():
        #tell user they need to be logged in to do 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 username is not None:
            try:
                userProfile = profileUtil.getProfileFromUser(User.objects.get(username=username))
            except ObjectDoesNotExist:
                context = {}
                context['object'] = 'profile'
                context.update(content.genBaseLoggedIn(request))
                return render_to_response("dne.html", context)
        else:
            userProfile = profileUtil.getProfileFromUser(request.user)
        toolsOwned = toolUtil.getAllToolsOwnedBy(userProfile)
        toolsBorrowed = toolUtil.getAllToolsBorrowedBy(userProfile)
        sheds = shedUtil.getAllShedsJoinedBy(userProfile)
        context = {}
        context.update(csrf(request))
        context['currentUser'] = request.user
        context['userProfile'] = userProfile
        context['toolsOwned'] = toolsOwned
        context['toolsBorrowed'] = toolsBorrowed
        context['sheds'] = sheds
        context.update(content.genBaseLoggedIn(request))
        return render_to_response('view_profile.html', context)
Example #6
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)
Example #7
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)
Example #8
0
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('/')
Example #9
0
def remove_shed_admin(request, id, username):
    if request.user.is_anonymous():
        return HttpResponseRedirect('/accounts/login')
    else:
        userProfile = profileUtil.getProfileFromUser(request.user)
        shedObj = shedUtil.getShedFromID(id)
        removeAdmin = profileUtil.getProfileFromUser(User.objects.get(username=username))
        if shedObj.owner == removeAdmin:
            return HttpResponseRedirect('/')
        else:
            if shedObj.owner == userProfile:
                shedUtil.removeAdminFromShed(shedObj, removeAdmin)
                notifUtil.createBadInfoNotif(shedObj, removeAdmin, "You have been removed as an admin from the shed " + shedObj.name + ". ")
                return HttpResponseRedirect('/sheds/' + str(shedObj.id) + '/remove_admin/removed/success')
            else:
                return HttpResponseRedirect('/')
Example #10
0
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)
Example #11
0
def tool_submission(request):
    if request.user.is_anonymous():
        #tell user they need to be logged in to do 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 request.method == 'POST':
            form = ToolCreationForm(request.user, request.POST)
            if form.is_valid():
                tool = form.save()
                tool.save()
                #send email
                sendMail(profileUtil.getProfileFromUser(request.user), \
                    "Your tool has been submitted! ",\
                     "Thanks for submitting your " + tool.name + \
                      " to ToolCloud.  We'll let you know when someone wants to borrow it.")
                return HttpResponseRedirect('/tools/' + str(tool.id) +
                                            '/success')
        else:
            form = ToolCreationForm(request.user)
        context = {}
        context.update(csrf(request))
        context.update(content.genBaseLoggedIn(request))
        context['form'] = form
        return render_to_response('tool_creation.html', context)
Example #12
0
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)
Example #13
0
 def __init__(self, user, *args, **kwargs):
     self.userObject = user
     self.profileObject = profileUtil.getProfileFromUser(self.userObject)
     self.userAddress = self.profileObject.streetAddress + ", " + self.profileObject.city + ", " + self.profileObject.state + \
        " " + self.profileObject.sharezone
     super(ShedCreationForm, self).__init__(*args, **kwargs)
     self.fields['location'] = forms.CharField(required=True, initial=self.userAddress, \
         help_text= 'The location of the shed.  Only visible to approved members.  Edit if not your own address.')
Example #14
0
def edit_user_info(request):
    if request.user.is_anonymous():
        return HttpResponseRedirect('/accounts/login/')
    else:
        if request.method == 'POST':
            profileObj = profileUtil.getProfileFromUser(request.user)
            form = UserEditForm(profileObj, request.POST)
            if form.is_valid():
                profileObj = form.save()
                return HttpResponseRedirect('/accounts/my_account/account_updated')
        else:
            form = UserEditForm(profileUtil.getProfileFromUser(request.user))
        context = {}
        context.update(csrf(request))
        context.update(content.genBaseLoggedIn(request))
        context['form'] = form
        return render_to_response('user_update.html', context)
Example #15
0
 def __init__(self, user, *args, **kwargs):
     self.userObject = user
     shedList = list(shedUtil.getAllShedsJoinedBy(profileUtil.getProfileFromUser(self.userObject)))
     self.shedChoiceList = []
     for shed in shedList:
         self.shedChoiceList.append((shed.id, shed.name))
     super(ToolCreationForm, self).__init__(*args, **kwargs)
     self.fields['shed'] = forms.ChoiceField(choices=self.shedChoiceList, help_text = 'The shed this tool will be a part of.')
Example #16
0
 def __init__(self, user, *args, **kwargs):
     self.userObject = user
     self.profileObject = profileUtil.getProfileFromUser(self.userObject)
     self.userAddress = self.profileObject.streetAddress + ", " + self.profileObject.city + ", " + self.profileObject.state + \
        " " + self.profileObject.sharezone
     super(ShedCreationForm, self).__init__(*args, **kwargs)
     self.fields['location'] = forms.CharField(required=True, initial=self.userAddress, \
         help_text= 'The location of the shed.  Only visible to approved members.  Edit if not your own address.')
Example #17
0
def add_shed_admin(request, id, username):
    if request.user.is_anonymous():
        return HttpResponseRedirect('/accounts/login')
    else:
        userProfile = profileUtil.getProfileFromUser(request.user)
        shedObj = shedUtil.getShedFromID(id)
        newAdmin = profileUtil.getProfileFromUser(User.objects.get(username=username))
        admins = shedUtil.getAllAdminsOfShed(shedObj)
        isAdmin = False
        for admin in admins:
            if admin == userProfile:
                isAdmin = True
        if isAdmin:
            shedObj.admins.add(newAdmin)
            notifUtil.createInfoNotif(shedObj, newAdmin, "You have been made an admin of the shed " + shedObj.name + "! ")
            return HttpResponseRedirect("/sheds/" + str(shedObj.id) + "/add_admin/added/success")
        else:
            return HttpResponseRedirect('/')
Example #18
0
def getNotifications(request):#returns a dict with the userProfile and notifs values filled
	if request.user.is_anonymous():#anon no notis
		return None
	userProfile = profileUtil.getProfileFromUser(request.user)
	notifs = notifUtil.getAllActiveProfileNotifs(userProfile)
	context = {}
	context['currentUserProfile'] = userProfile
	context['notifs'] = notifs
	return context
Example #19
0
def borrow_tool(request, id):
    if request.user.is_anonymous():
        return HttpResponseRedirect('/accounts/login')
    else:
        borrowerProfile = profileUtil.getProfileFromUser(request.user)
        toolObject = toolUtil.getToolFromID(id)
        ownerProfile = toolObject.owner
        actionObject = actionUtil.createBorrowRequestAction(toolObject, borrowerProfile)
        return HttpResponseRedirect('/tools/' + id + '/request_sent')
Example #20
0
def edit_user_info(request):
    if request.user.is_anonymous():
        return HttpResponseRedirect('/accounts/login/')
    else:
        if request.method == 'POST':
            profileObj = profileUtil.getProfileFromUser(request.user)
            form = UserEditForm(profileObj, request.POST)
            if form.is_valid():
                profileObj = form.save()
                return HttpResponseRedirect(
                    '/accounts/my_account/account_updated')
        else:
            form = UserEditForm(profileUtil.getProfileFromUser(request.user))
        context = {}
        context.update(csrf(request))
        context.update(content.genBaseLoggedIn(request))
        context['form'] = form
        return render_to_response('user_update.html', context)
Example #21
0
def confirm_leave_shed(request, id):
    if request.user.is_anonymous():
        return HttpResponseRedirect('/accounts/login')
    else:
        userProfile = profileUtil.getProfileFromUser(request.user)
        shedObj = shedUtil.getShedFromID(id)
        context = {}
        context['currentUser'] = userProfile
        context['shed'] = shedObj
        return render_to_response("leave_shed_confirm.html", context)
Example #22
0
def borrow_tool(request, id):
    if request.user.is_anonymous():
        return HttpResponseRedirect('/accounts/login')
    else:
        borrowerProfile = profileUtil.getProfileFromUser(request.user)
        toolObject = toolUtil.getToolFromID(id)
        ownerProfile = toolObject.owner
        actionObject = actionUtil.createBorrowRequestAction(
            toolObject, borrowerProfile)
        return HttpResponseRedirect('/tools/' + id + '/request_sent')
Example #23
0
def join_shed(request, id):
    if request.user.is_anonymous():
        return HttpResponseRedirect('/accounts/login')
    else:
        joinerProfile = profileUtil.getProfileFromUser(request.user)
        shedObject = shedUtil.getShedFromID(id)
        ownerProfile = shedObject.owner
        actionObject = actionUtil.createShedRequestAction(shedObject, joinerProfile)
        actionManager.processActions()
        return HttpResponseRedirect('/sheds/' + id + '/request_sent')
Example #24
0
def confirm_leave_shed(request, id):
    if request.user.is_anonymous():
        return HttpResponseRedirect('/accounts/login')
    else:
        userProfile = profileUtil.getProfileFromUser(request.user)
        shedObj = shedUtil.getShedFromID(id)
        context = {}
        context['currentUser'] = userProfile
        context['shed'] = shedObj
        return render_to_response("leave_shed_confirm.html", context)
Example #25
0
def confirm_remove_shed_admin(request, id, username):
    if request.user.is_anonymous():
        return HttpResponseRedirect('/accounts/login')
    else:
        userProfile = profileUtil.getProfileFromUser(request.user)
        shedObj = shedUtil.getShedFromID(id)
        removeAdmin = profileUtil.getProfileFromUser(User.objects.get(username=username))
        if shedObj.owner == removeAdmin:
            return HttpResponseRedirect('/')
        else:
            if shedObj.owner == userProfile:
                context = {}
                context['currentUser'] = userProfile
                context['shed'] = shedObj
                context['removeAdmin'] = removeAdmin
                context.update(content.genBaseLoggedIn(request))
                return render_to_response("admin_remove_confirm.html", context)
            else:
                return HttpResponseRedirect('/')
Example #26
0
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('/')
Example #27
0
def getNotifications(
        request
):  #returns a dict with the userProfile and notifs values filled
    if request.user.is_anonymous():  #anon no notis
        return None
    userProfile = profileUtil.getProfileFromUser(request.user)
    notifs = notifUtil.getAllActiveProfileNotifs(userProfile)
    context = {}
    context['currentUserProfile'] = userProfile
    context['notifs'] = notifs
    return context
Example #28
0
def join_shed(request, id):
    if request.user.is_anonymous():
        return HttpResponseRedirect('/accounts/login')
    else:
        joinerProfile = profileUtil.getProfileFromUser(request.user)
        shedObject = shedUtil.getShedFromID(id)
        ownerProfile = shedObject.owner
        actionObject = actionUtil.createShedRequestAction(
            shedObject, joinerProfile)
        actionManager.processActions()
        return HttpResponseRedirect('/sheds/' + id + '/request_sent')
Example #29
0
def confirm_remove_shed_admin(request, id, username):
    if request.user.is_anonymous():
        return HttpResponseRedirect('/accounts/login')
    else:
        userProfile = profileUtil.getProfileFromUser(request.user)
        shedObj = shedUtil.getShedFromID(id)
        removeAdmin = profileUtil.getProfileFromUser(
            User.objects.get(username=username))
        if shedObj.owner == removeAdmin:
            return HttpResponseRedirect('/')
        else:
            if shedObj.owner == userProfile:
                context = {}
                context['currentUser'] = userProfile
                context['shed'] = shedObj
                context['removeAdmin'] = removeAdmin
                context.update(content.genBaseLoggedIn(request))
                return render_to_response("admin_remove_confirm.html", context)
            else:
                return HttpResponseRedirect('/')
Example #30
0
def remove_shed_admin(request, id, username):
    if request.user.is_anonymous():
        return HttpResponseRedirect('/accounts/login')
    else:
        userProfile = profileUtil.getProfileFromUser(request.user)
        shedObj = shedUtil.getShedFromID(id)
        removeAdmin = profileUtil.getProfileFromUser(
            User.objects.get(username=username))
        if shedObj.owner == removeAdmin:
            return HttpResponseRedirect('/')
        else:
            if shedObj.owner == userProfile:
                shedUtil.removeAdminFromShed(shedObj, removeAdmin)
                notifUtil.createBadInfoNotif(
                    shedObj, removeAdmin,
                    "You have been removed as an admin from the shed " +
                    shedObj.name + ". ")
                return HttpResponseRedirect('/sheds/' + str(shedObj.id) +
                                            '/remove_admin/removed/success')
            else:
                return HttpResponseRedirect('/')
Example #31
0
def confirm_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)
        isAdmin = False
        for admin in admins:
            if admin == userProfile:
                isAdmin = True
        if isAdmin:
            context = {}
            context['currentUser'] = userProfile
            context['shed'] = shedObj
            context['banned'] = banUser
            context.update(content.genBaseLoggedIn(request))
            return render_to_response("remove_member_confirm.html", context)
        else:
            return HttpResponseRedirect('/')
Example #32
0
 def __init__(self, user, *args, **kwargs):
     self.userObject = user
     shedList = list(
         shedUtil.getAllShedsJoinedBy(
             profileUtil.getProfileFromUser(self.userObject)))
     self.shedChoiceList = []
     for shed in shedList:
         self.shedChoiceList.append((shed.id, shed.name))
     super(ToolCreationForm, self).__init__(*args, **kwargs)
     self.fields['shed'] = forms.ChoiceField(
         choices=self.shedChoiceList,
         help_text='The shed this tool will be a part of.')
Example #33
0
def confirm_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)
        isAdmin = False
        for admin in admins:
            if admin == userProfile:
                isAdmin = True
        if isAdmin:
            context = {}
            context['currentUser'] = userProfile
            context['shed'] = shedObj
            context['banned'] = banUser
            context.update(content.genBaseLoggedIn(request))
            return render_to_response("remove_member_confirm.html", context)
        else:
            return HttpResponseRedirect('/')
Example #34
0
def add_shed_admin(request, id, username):
    if request.user.is_anonymous():
        return HttpResponseRedirect('/accounts/login')
    else:
        userProfile = profileUtil.getProfileFromUser(request.user)
        shedObj = shedUtil.getShedFromID(id)
        newAdmin = profileUtil.getProfileFromUser(
            User.objects.get(username=username))
        admins = shedUtil.getAllAdminsOfShed(shedObj)
        isAdmin = False
        for admin in admins:
            if admin == userProfile:
                isAdmin = True
        if isAdmin:
            shedObj.admins.add(newAdmin)
            notifUtil.createInfoNotif(
                shedObj, newAdmin, "You have been made an admin of the shed " +
                shedObj.name + "! ")
            return HttpResponseRedirect("/sheds/" + str(shedObj.id) +
                                        "/add_admin/added/success")
        else:
            return HttpResponseRedirect('/')
Example #35
0
def genBaseLoggedIn(request):
	results = dict()
	results.update(genSuper())
	results['username'] = request.user.username
	results['community'] = profileUtil.getSharezone(profileUtil.getProfileFromUser(request.user))
	results['first_name'] = request.user.first_name
	results['last_name'] = request.user.last_name
	#get pict location
	results['picture'] = None
	#get top sheds
	results['topSheds'] = None
	#get notifications
	results.update(getNotifications(request))
	return results
Example #36
0
def user_register(request):
    if request.user.is_anonymous():
        if request.method == 'POST':
            form = UserRegistrationForm(request.POST)
            if form.is_valid():
                userAccount = form.save()
                user = authenticate(username=form.cleaned_data['username'],
                                    password=form.cleaned_data['password1'])
                if user is not None:
                    login(request, user)
                #send confirmation email
                sendMail(profileUtil.getProfileFromUser(userAccount), \
                    "Welcome aboard! ", "Thank you for registering with ToolCloud.")
                shedName = form.cleaned_data['username'] + "'s Shed"
                userProfile = profileUtil.getProfileFromUser(userAccount)
                newShedObject = Shed(name=shedName, owner=userProfile, location='location', sharezone=form.cleaned_data['zip_code'],\
                    status='status')
                newShedObject.save()
                newShedObject.members.add(userProfile)
                newShedObject.admins.add(userProfile)
                newShedObject.save()
                userProfile.personalShed = newShedObject
                context = {}
                context.update(content.genUserHome(request))
                context.update(content.addGoodRegisterNoti(dict()))
                return render_to_response('userHome.html', context)
        else:
            form = UserRegistrationForm()
        context = {}
        context.update(csrf(request))
        context['form'] = form
        context.update(content.genSuper())
        #Pass the context to a template
        return render_to_response('register.html', context)
    else:
        return HttpResponseRedirect('/')
Example #37
0
def genBaseLoggedIn(request):
    results = dict()
    results.update(genSuper())
    results['username'] = request.user.username
    results['community'] = profileUtil.getSharezone(
        profileUtil.getProfileFromUser(request.user))
    results['first_name'] = request.user.first_name
    results['last_name'] = request.user.last_name
    #get pict location
    results['picture'] = None
    #get top sheds
    results['topSheds'] = None
    #get notifications
    results.update(getNotifications(request))
    return results
Example #38
0
def all_sheds(request):
    if request.user.is_anonymous():
        return HttpResponseRedirect('/accounts/login')
    else:
        userProfile = profileUtil.getProfileFromUser(request.user)
        allSheds = shedUtil.getAllShedsAllSharezones()
        shedsInMySharezone = shedUtil.getAllShedsInSharezone(userProfile.sharezone)
        adminSheds = shedUtil.getAllShedsAdministratedBy(userProfile)
        ownedSheds = shedUtil.getAllShedsOwnedBy(userProfile)
        memberSheds = shedUtil.getAllShedsJoinedBy(userProfile)
        context = {}
        context.update(csrf(request))
        context['sheds'] = allSheds
        context['adminSheds'] = adminSheds
        context['ownedSheds'] = ownedSheds
        context['mySheds'] = memberSheds
        context.update(content.genBaseLoggedIn(request))
        return render_to_response('all_sheds.html', context)
Example #39
0
def all_sheds(request):
    if request.user.is_anonymous():
        return HttpResponseRedirect('/accounts/login')
    else:
        userProfile = profileUtil.getProfileFromUser(request.user)
        allSheds = shedUtil.getAllShedsAllSharezones()
        shedsInMySharezone = shedUtil.getAllShedsInSharezone(
            userProfile.sharezone)
        adminSheds = shedUtil.getAllShedsAdministratedBy(userProfile)
        ownedSheds = shedUtil.getAllShedsOwnedBy(userProfile)
        memberSheds = shedUtil.getAllShedsJoinedBy(userProfile)
        context = {}
        context.update(csrf(request))
        context['sheds'] = allSheds
        context['adminSheds'] = adminSheds
        context['ownedSheds'] = ownedSheds
        context['mySheds'] = memberSheds
        context.update(content.genBaseLoggedIn(request))
        return render_to_response('all_sheds.html', context)
Example #40
0
 def save(self,commit = True):
     tool = super(ToolCreationForm, self).save(commit = False)
     tool.owner = profileUtil.getProfileFromUser(self.userObject)
     tool.timeCreated = timezone.now()
     tool.timeLastEdited = timezone.now()
     tool.condition = self.cleaned_data['condition']
     tool.conditionReadable = CONDITION_DICT[int(self.cleaned_data['condition'])]
     tool.maxBorrowTime = self.cleaned_data['maximum_borrow_time']
     tool.minimumReputation = self.cleaned_data['minimum_reputation']
     tool.isAvailable = 1
     tool.myShed = shedUtil.getShedFromID(self.cleaned_data['shed'])
     tool.location = shedUtil.getLocationOfShed(tool.myShed)
     tool.picture = ''
     tool.borrowedCount = 0
     tool.requestedCount = 0
     tool.preferences = ''
     if commit:
         tool.save()
     return tool
Example #41
0
def genUserHome(request):
	results = genBaseLoggedIn(request)
	profile = profileUtil.getProfileFromUser(request.user)
	tools = toolUtil.getAllToolsOwnedBy(profile)
	sheds = shedUtil.getAllShedsJoinedBy(profile)
	#sheds = None
	borrowedTools = toolUtil.getAllToolsBorrowedBy(profile)
	#borrowedTools = None
	#print(profile)
	#results['notif'] = notifUtil.getAllActiveProfileNotifs(profile)
	sharezone = profileUtil.getSharezone(profile)
	sharezoneMembers = profileUtil.getAllProfilesInSharezone(sharezone)
	#not done
	results['tools'] = tools
	results['sheds'] = sheds
	results['borrowed'] = borrowedTools
	results['sharezone'] = sharezone
	results['sharezoneMembers'] = sharezoneMembers
	return results
Example #42
0
def genUserHome(request):
    results = genBaseLoggedIn(request)
    profile = profileUtil.getProfileFromUser(request.user)
    tools = toolUtil.getAllToolsOwnedBy(profile)
    sheds = shedUtil.getAllShedsJoinedBy(profile)
    #sheds = None
    borrowedTools = toolUtil.getAllToolsBorrowedBy(profile)
    #borrowedTools = None
    #print(profile)
    #results['notif'] = notifUtil.getAllActiveProfileNotifs(profile)
    sharezone = profileUtil.getSharezone(profile)
    sharezoneMembers = profileUtil.getAllProfilesInSharezone(sharezone)
    #not done
    results['tools'] = tools
    results['sheds'] = sheds
    results['borrowed'] = borrowedTools
    results['sharezone'] = sharezone
    results['sharezoneMembers'] = sharezoneMembers
    return results
Example #43
0
 def save(self, commit=True):
     tool = super(ToolCreationForm, self).save(commit=False)
     tool.owner = profileUtil.getProfileFromUser(self.userObject)
     tool.timeCreated = timezone.now()
     tool.timeLastEdited = timezone.now()
     tool.condition = self.cleaned_data['condition']
     tool.conditionReadable = CONDITION_DICT[int(
         self.cleaned_data['condition'])]
     tool.maxBorrowTime = self.cleaned_data['maximum_borrow_time']
     tool.minimumReputation = self.cleaned_data['minimum_reputation']
     tool.isAvailable = 1
     tool.myShed = shedUtil.getShedFromID(self.cleaned_data['shed'])
     tool.location = shedUtil.getLocationOfShed(tool.myShed)
     tool.picture = ''
     tool.borrowedCount = 0
     tool.requestedCount = 0
     tool.preferences = ''
     if commit:
         tool.save()
     return tool
Example #44
0
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')
Example #45
0
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')
Example #46
0
def password_reset(request):
    if request.user.is_anonymous():
        return HttpResponseRedirect('/accounts/login')
    # if this is a POST request we need to process the form data
    if request.method == 'POST':
        # create a form instance and populate it with data from the request:
        form = passwordResetForm(request.POST)
        # check whether it's valid:
        if form.is_valid():
            passone = form.cleaned_data.get ("password")
            passtoo = form.cleaned_data.get ("confirm_password")
            if (passone == passtoo):
                request.user.set_password (passone)
                request.user.save()
                sendMail(profileUtil.getProfileFromUser(request.user), \
                    "Your password has been changed", \
                    "Your password has been changed on ToolCloud.")
            return HttpResponseRedirect('/accounts/my_account/password_changed')
    # if a GET (or any other method) we'll create a blank form
    else:
        form = passwordResetForm()

    return render(request, 'password_reset.html', {'form': form})
Example #47
0
def tool_submission(request):
    if request.user.is_anonymous():
        #tell user they need to be logged in to do 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 request.method == 'POST':
            form = ToolCreationForm(request.user, request.POST)
            if form.is_valid():
                tool = form.save()
                tool.save()
                #send email
                sendMail(profileUtil.getProfileFromUser(request.user), \
                    "Your tool has been submitted! ",\
                     "Thanks for submitting your " + tool.name + \
                      " to ToolCloud.  We'll let you know when someone wants to borrow it.")
                return HttpResponseRedirect('/tools/' + str(tool.id) + '/success')
        else:
            form = ToolCreationForm(request.user)
        context = {}
        context.update(csrf(request))
        context.update(content.genBaseLoggedIn(request))
        context['form'] = form
        return render_to_response('tool_creation.html', context)
Example #48
0
def password_reset(request):
    if request.user.is_anonymous():
        return HttpResponseRedirect('/accounts/login')
    # if this is a POST request we need to process the form data
    if request.method == 'POST':
        # create a form instance and populate it with data from the request:
        form = passwordResetForm(request.POST)
        # check whether it's valid:
        if form.is_valid():
            passone = form.cleaned_data.get("password")
            passtoo = form.cleaned_data.get("confirm_password")
            if (passone == passtoo):
                request.user.set_password(passone)
                request.user.save()
                sendMail(profileUtil.getProfileFromUser(request.user), \
                    "Your password has been changed", \
                    "Your password has been changed on ToolCloud.")
            return HttpResponseRedirect(
                '/accounts/my_account/password_changed')
    # if a GET (or any other method) we'll create a blank form
    else:
        form = passwordResetForm()

    return render(request, 'password_reset.html', {'form': form})
 def test_GetUserOfProfile(self):
     """
     """
     self.assertEqual(profUtils.getProfileFromUser(profUtils.getUserofProfile(self.genProfile)), self.genProfile)
Example #50
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)
Example #51
0
 def test_GetUserOfProfile(self):
     """
     """
     self.assertEqual(
         profUtils.getProfileFromUser(
             profUtils.getUserofProfile(self.genProfile)), self.genProfile)
Example #52
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)