Exemplo n.º 1
0
def request_allocation(request):
    """
    View to handle all allocation requests.

    Requires user to be logged in to help properly identify who is doing the request.  All user must already have
     accounts to be recognize to prevent ambiguity in requesting collaborators.  The submittor and submit ip are
     pulled from the request and are require for the form to save.

    """
    this_context = {}

    if request.method == 'POST':
        #Make sure the logged in user and the source ip get added to the post data
        data=request.POST
        pre_process_errors=[]
        try:
            if request.user.id==1:
                data['submittor']=73
            else:
                data['submittor']=ProjectUser.objects.get(username=request.user.username).id
        except ProjectUser.DoesNotExist:
            pre_process_errors.append("Error user %s does not seem to be in the allocation system, please inform your \
                                system admins" % request.user.username)

        try:
            data['submit_ip']=request.META['HTTP_X_FORWARDED_FOR']
        except:
            data['submit_ip']=request.META['REMOTE_ADDR']

        ar_form = AllocationRequestForm(data, request.FILES)
        if (not pre_process_errors) and ar_form.is_valid(): #If valid then save an allocation request and redirect to the sucess page
            allocation_request = ar_form.save()
	    responses=allocation_request_created.send(sender=allocation_request)
            this_context.update({'allocation_request':allocation_request})
            return render(request,'confirmation.html', this_context)
        else: #Form not valid, pass it on with its errors
            print ar_form._errors
            for err in pre_process_errors:
                messages.error(request,err)
            this_context.update({'form':ar_form})

    else: #If method is GET then just create the form
        init_data = {}
        init_data['user']=request.user.id
        this_context.update({'form': AllocationRequestForm(initial=init_data)})

    return render(request,'allocationrequest.html', this_context)
Exemplo n.º 2
0
def request_startup_allocation(request):

    this_context = {}
    first_name = ProjectUser.objects.get(username=request.user.username).first_name
    last_name = ProjectUser.objects.get(username=request.user.username).last_name
    request_user = first_name + " " + last_name
#    request_user=request.user.username

    if request.method=='POST':
        data=request.POST
        pre_process_errors=[]
        try:
            if request.user.id==1:
                data['submittor']=73
            else:
                data['submittor']=ProjectUser.objects.get(username=request.user.username).id
        except ProjectUser.DoesNotExist:
            pre_process_errors.append("Error user %s does not seem to be in the allocation system, please inform your \
                                system admins" % request.user.username)

        try:
            data['submit_ip']=request.META['HTTP_X_FORWARDED_FOR']
        except:
            data['submit_ip']=request.META['REMOTE_ADDR']

        ar_form = AllocationRequestForm(data, request.FILES)
        if (not pre_process_errors) and ar_form.is_valid(): #If valid then save an allocation request and redirect to the sucess page
            allocation_request = ar_form.save()
            allocation_request_received.send(sender=allocation_request,allocation_request=allocation_request)
            this_context.update({'allocation_request':allocation_request})
            return render(request,'confirmation.html', this_context)
        else: #Form not valid, pass it on with its errors
            print ar_form._errors
            for err in pre_process_errors:
                messages.error(request,err)
            this_context.update({'form':ar_form})

    else: #If method is GET then just create the form
        init_data = {}
        init_data['user']=request.user.id
        this_context.update({'form': AllocationRequestForm(initial=init_data)})

    return render(request,'allocationrequest1.html', this_context)