Example #1
0
 def save(self, commit = True):
     self.toolObject.name = self.cleaned_data['name_']
     self.toolObject.description = self.cleaned_data['description_']
     self.toolObject.tags = self.cleaned_data['tags_']
     self.toolObject.condition = self.cleaned_data['condition']
     self.toolObject.conditionReadable = CONDITION_DICT[int(self.cleaned_data['condition'])]
     self.toolObject.maxBorrowTime = self.cleaned_data['maximum_borrow_time']
     self.toolObject.minimumReputation = self.cleaned_data['minimum_reputation']
     self.toolObject.myShed = shedUtil.getShedFromID(self.cleaned_data['shed'])
     self.profileObject.location = shedUtil.getShedFromID(self.cleaned_data['shed']).location
     if commit:
         self.toolObject.save()
     return self.toolObject 
Example #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)
Example #3
0
def edit_shed(request, id):
    if request.user.is_anonymous():
        return HttpResponseRedirect('/accounts/login/')
    else:
        if request.method == 'POST':
            shedObj = shedUtil.getShedFromID(id)
            form = ShedEditForm(shedObj, request.POST)
            if form.is_valid():
                shedObj = form.save()
                return HttpResponseRedirect('/sheds/' + str(shedObj.id) + '/edit/success')
        else:
            form = ShedEditForm(shedUtil.getShedFromID(id))
        context = {}
        context.update(csrf(request))
        context.update(content.genBaseLoggedIn(request))
        context['form'] = form
        context['shed'] = shedUtil.getShedFromID(id)
        return render_to_response('shed_update.html', context)
Example #4
0
 def save(self, commit=True):
     self.toolObject.name = self.cleaned_data['name_']
     self.toolObject.description = self.cleaned_data['description_']
     self.toolObject.tags = self.cleaned_data['tags_']
     self.toolObject.condition = self.cleaned_data['condition']
     self.toolObject.conditionReadable = CONDITION_DICT[int(
         self.cleaned_data['condition'])]
     self.toolObject.maxBorrowTime = self.cleaned_data[
         'maximum_borrow_time']
     self.toolObject.minimumReputation = self.cleaned_data[
         'minimum_reputation']
     self.toolObject.myShed = shedUtil.getShedFromID(
         self.cleaned_data['shed'])
     self.profileObject.location = shedUtil.getShedFromID(
         self.cleaned_data['shed']).location
     if commit:
         self.toolObject.save()
     return self.toolObject
Example #5
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 #6
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 #7
0
def edit_shed(request, id):
    if request.user.is_anonymous():
        return HttpResponseRedirect('/accounts/login/')
    else:
        if request.method == 'POST':
            shedObj = shedUtil.getShedFromID(id)
            form = ShedEditForm(shedObj, request.POST)
            if form.is_valid():
                shedObj = form.save()
                return HttpResponseRedirect('/sheds/' + str(shedObj.id) +
                                            '/edit/success')
        else:
            form = ShedEditForm(shedUtil.getShedFromID(id))
        context = {}
        context.update(csrf(request))
        context.update(content.genBaseLoggedIn(request))
        context['form'] = form
        context['shed'] = shedUtil.getShedFromID(id)
        return render_to_response('shed_update.html', context)
Example #8
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 #9
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 #10
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 #11
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 #12
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 #13
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 #14
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 #15
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 #16
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 #17
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 #18
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 #19
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 #20
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 #21
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 #22
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 #23
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 #24
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('/')