コード例 #1
0
def approveRequest(request, message_id, toolId):
    """ Called when tool request is approved
    """

    message = AlertMessage.objects.get(id=message_id)
    sender = message.sender
    currTool = ToolModel.objects.get(id=message.toolId)
    if not (request.user.is_authenticated()):
        return HttpResponseRedirect('/login/')
    else:
        existingReservations = Reservation.objects.filter(
            tool_id=message.toolId)
        currentUser = UserProfile.objects.get(user_id=request.user.id)
        for r in existingReservations:
            if not ((message.startDate < r.startDate
                     and message.endDate < r.startDate) or
                    (message.startDate >= r.endDate
                     and message.endDate > r.endDate)):
                return HttpResponseRedirect('/messagecenter/')

    content = (User.objects.get(id=currentUser.user_id).username) + " has approved of your request to borrow " + ToolModel.objects.get(id=toolId).name\
         + " from " + message.startDate.strftime("%m/%d/%y") + " to " + message.endDate.strftime("%m/%d/%y") + '.'

    try:
        t = ToolModel.objects.get(id=toolId)
        #t.available = False
        #t.save()

        Reservation.create(currTool, sender, message.startDate,
                           message.endDate).save()

        AlertMessage.create(currentUser,
                            UserProfile.objects.get(user_id=sender.user_id),
                            "Request Approved", content, False, 0).save()

        sender.timesBorrowed += 1
        sender.save()

        currentUser.timesLent += 1
        currentUser.save()

        t.timesUsed += 1
        t.save()
    except:
        return HttpResponseRedirect('ERROR')

    return HttpResponseRedirect('/messagecenter/delete/' + message_id)
コード例 #2
0
ファイル: views.py プロジェクト: jcdesimp/SEToolShare
def approveRequest(request, message_id, toolId):
    """ Called when tool request is approved
    """

    message=AlertMessage.objects.get(id=message_id)
    sender=message.sender
    currTool=ToolModel.objects.get(id=message.toolId)
    if not (request.user.is_authenticated()):
        return HttpResponseRedirect('/login/')
    else:
        existingReservations = Reservation.objects.filter(tool_id=message.toolId)
        currentUser = UserProfile.objects.get(user_id=request.user.id)
        for r in existingReservations:
                if not ((message.startDate < r.startDate and message.endDate < r.startDate) or (message.startDate >= r.endDate and message.endDate > r.endDate)):
                        return HttpResponseRedirect('/messagecenter/')
        
    content = (User.objects.get(id=currentUser.user_id).username) + " has approved of your request to borrow " + ToolModel.objects.get(id=toolId).name\
         + " from " + message.startDate.strftime("%m/%d/%y") + " to " + message.endDate.strftime("%m/%d/%y") + '.'

    try:
        t = ToolModel.objects.get(id=toolId)
        #t.available = False
        #t.save()
        
        Reservation.create(currTool, sender, message.startDate, message.endDate).save()
        
        AlertMessage.create(currentUser, UserProfile.objects.get(user_id=sender.user_id), "Request Approved", content, False, 0).save()
        
        sender.timesBorrowed += 1
        sender.save()
        
        currentUser.timesLent += 1
        currentUser.save()
        
        t.timesUsed += 1
        t.save()
    except:
        return HttpResponseRedirect('ERROR')
    
    return HttpResponseRedirect('/messagecenter/delete/'+message_id)
コード例 #3
0
ファイル: views.py プロジェクト: jcdesimp/SEToolShare
def sendToolRequest(request, toolId):
    """ Called to send a request for a tool
    """

    if not (request.user.is_authenticated()):
        return HttpResponseRedirect('/login/')
    else:
        currentUser = UserProfile.objects.get(user_id=request.user.id)
        currTool = ToolModel.objects.get(id=toolId)
    curRes = Reservation.objects.filter(tool_id=toolId, endDate__gt=date.today())
    conflictingReservations = []
        
    if request.method == 'POST':                 # If the form has been submitted...
        form = MakeRequest(request.POST)         # A form bound to the POST data
        if form.is_valid():                     # All validation rules pass
            startDate = form.cleaned_data['startDate']
            endDate = form.cleaned_data['endDate']
            message = form.cleaned_data['message']
            
            if message != "":
                message = "Personal message for tool request: " + message
            else:
                message = ""
            
            if (endDate < startDate):
                form = MakeRequest()
                return render(request, 'messageCenter/sendRequest.html', {
                    'form': form, 'toolId': toolId, 'conflict': True, 'conflicts': conflictingReservations, 'curRes': curRes, 'tool': ToolModel.objects.get(id=toolId)
                })
            

            existingReservations = Reservation.objects.filter(tool_id=toolId)
            
            for r in existingReservations:
                if not ((startDate < r.startDate and endDate < r.startDate) or (startDate >= r.endDate and endDate > r.endDate)):
                        conflictingReservations.append(r)          
                    
            if len(conflictingReservations) > 0:
                form = MakeRequest()
                return render(request, 'messageCenter/sendRequest.html', {
                    'form': form, 'toolId': toolId, 'conflict': True, 'conflicts': conflictingReservations, 'curRes':curRes, 'tool': ToolModel.objects.get(id=toolId)
                })
              
            
            if currTool.inShed():
                Reservation.create(currTool, currentUser, startDate, endDate).save()
                content = User.objects.get(id=currentUser.user_id).username + " is borrowing "\
                 + ToolModel.objects.get(id=toolId).name + "  from your shed from " + startDate.strftime("%m/%d/%y") \
                 + " to " + endDate.strftime("%m/%d/%y") + ".\n" + message
                
                shed = CommunityShed.objects.get(id=currTool.location_id)
                messages.add_message(request, messages.INFO, 'Your reservation has been created.', extra_tags='alert-success')
                AlertMessage.create(currentUser, UserProfile.objects.get(id=shed.owner_id), "Message", content, False, toolId, startDate, endDate).save()
                
                currentUser.timesBorrowed += 1
                currentUser.save()
        
                currTool.timesUsed += 1
                currTool.save()
                
                return HttpResponseRedirect('/tooldirectory/')
                
            if not currTool.inShed():
                content = (User.objects.get(id=currentUser.user_id).username) + " has requested to borrow your "\
                    + ToolModel.objects.get(id=toolId).name + " from " + startDate.strftime("%m/%d/%y") + " to " + endDate.strftime("%m/%d/%y") + ".\n" + message

                messages.add_message(request, messages.INFO, 'Your request has been sent.', extra_tags='alert-success')
                AlertMessage.create(currentUser, UserProfile.objects.get(id=currTool.owner_id), "Request", content, True, toolId, startDate, endDate).save()

                
                return HttpResponseRedirect('/tooldirectory/')     # Redirect after POST
    else:
        form = MakeRequest()                     # An unbound form
        
    return render(request, 'messageCenter/sendRequest.html', {
        'form': form, 'toolId': toolId, 'conflict': False, 'curRes':curRes, 'tool': ToolModel.objects.get(id=toolId)
    })
コード例 #4
0
def sendToolRequest(request, toolId):
    """ Called to send a request for a tool
    """

    if not (request.user.is_authenticated()):
        return HttpResponseRedirect('/login/')
    else:
        currentUser = UserProfile.objects.get(user_id=request.user.id)
        currTool = ToolModel.objects.get(id=toolId)
    curRes = Reservation.objects.filter(tool_id=toolId,
                                        endDate__gt=date.today())
    conflictingReservations = []

    if request.method == 'POST':  # If the form has been submitted...
        form = MakeRequest(request.POST)  # A form bound to the POST data
        if form.is_valid():  # All validation rules pass
            startDate = form.cleaned_data['startDate']
            endDate = form.cleaned_data['endDate']
            message = form.cleaned_data['message']

            if message != "":
                message = "Personal message for tool request: " + message
            else:
                message = ""

            if (endDate < startDate):
                form = MakeRequest()
                return render(
                    request, 'messageCenter/sendRequest.html', {
                        'form': form,
                        'toolId': toolId,
                        'conflict': True,
                        'conflicts': conflictingReservations,
                        'curRes': curRes,
                        'tool': ToolModel.objects.get(id=toolId)
                    })

            existingReservations = Reservation.objects.filter(tool_id=toolId)

            for r in existingReservations:
                if not ((startDate < r.startDate and endDate < r.startDate) or
                        (startDate >= r.endDate and endDate > r.endDate)):
                    conflictingReservations.append(r)

            if len(conflictingReservations) > 0:
                form = MakeRequest()
                return render(
                    request, 'messageCenter/sendRequest.html', {
                        'form': form,
                        'toolId': toolId,
                        'conflict': True,
                        'conflicts': conflictingReservations,
                        'curRes': curRes,
                        'tool': ToolModel.objects.get(id=toolId)
                    })

            if currTool.inShed():
                Reservation.create(currTool, currentUser, startDate,
                                   endDate).save()
                content = User.objects.get(id=currentUser.user_id).username + " is borrowing "\
                 + ToolModel.objects.get(id=toolId).name + "  from your shed from " + startDate.strftime("%m/%d/%y") \
                 + " to " + endDate.strftime("%m/%d/%y") + ".\n" + message

                shed = CommunityShed.objects.get(id=currTool.location_id)
                messages.add_message(request,
                                     messages.INFO,
                                     'Your reservation has been created.',
                                     extra_tags='alert-success')
                AlertMessage.create(currentUser,
                                    UserProfile.objects.get(id=shed.owner_id),
                                    "Message", content, False, toolId,
                                    startDate, endDate).save()

                currentUser.timesBorrowed += 1
                currentUser.save()

                currTool.timesUsed += 1
                currTool.save()

                return HttpResponseRedirect('/tooldirectory/')

            if not currTool.inShed():
                content = (User.objects.get(id=currentUser.user_id).username) + " has requested to borrow your "\
                    + ToolModel.objects.get(id=toolId).name + " from " + startDate.strftime("%m/%d/%y") + " to " + endDate.strftime("%m/%d/%y") + ".\n" + message

                messages.add_message(request,
                                     messages.INFO,
                                     'Your request has been sent.',
                                     extra_tags='alert-success')
                AlertMessage.create(
                    currentUser, UserProfile.objects.get(id=currTool.owner_id),
                    "Request", content, True, toolId, startDate,
                    endDate).save()

                return HttpResponseRedirect(
                    '/tooldirectory/')  # Redirect after POST
    else:
        form = MakeRequest()  # An unbound form

    return render(
        request, 'messageCenter/sendRequest.html', {
            'form': form,
            'toolId': toolId,
            'conflict': False,
            'curRes': curRes,
            'tool': ToolModel.objects.get(id=toolId)
        })