def ResourceBidRegister(request): errors = [] form = ResourceBidDetailsForm() #display all registered machines of user machines = displayProviderMachines(request) p_ID = getProviderID(request)['providerID'] resource = Resource.objects.filter(providerID = p_ID) #print a if not getProviderID(request)['bool']: errors.append('First Register for Provider') elif request.method == 'POST': form = ResourceBidDetailsForm(request.POST) if form.is_valid(): r_ID = request.POST['resourceID'] r_ID = Resource.objects.get(resourceID = r_ID) sdt = form.cleaned_data['startDateTime'] edt = form.cleaned_data['endDateTime'] sp = form.cleaned_data['startPrice'] if getMachineID(r_ID)['bool']: machineID = getMachineID(r_ID)['machineID'] machineID.startDateTime = sdt machineID.endDateTime = edt machineID.startPrice = sp machineID.save() else: insert = ResourceBidDetails(resourceID = r_ID,providerID = p_ID, startDateTime = sdt, endDateTime = edt, startPrice = sp) insert.save() resourceObj = Resource.objects.get(resourceID = r_ID) resourceObj.availability = 'A' resourceObj.save() return HttpResponseRedirect('/') else: form = ResourceBidDetailsForm() return render_to_response("bidding/bidding_details.html",{'form':form, 'errors':errors,'resource': resource,'machines' : machines},context_instance = RequestContext(request))
def displayProviderMachines(request): try: machines = [] p_ID = getProviderID(request)['providerID'] machines = ResourceBidDetails.objects.filter(providerID = p_ID) return machines except ResourceBidDetails.DoesNotExist: return False
def ResourceRegister(request): errors = [] form = ResourceForm() if not getProviderID(request)['bool']: errors.append('First Register for Provider') elif request.method == 'POST': form = ResourceForm(request.POST) if form.is_valid(): r_ID = form.cleaned_data['resourceID'] p_ID = getProviderID(request)['providerID'] avail = form.cleaned_data['availability'] insert = Resource(resourceID = r_ID, providerID = p_ID, availability = avail) insert.save() return HttpResponseRedirect('/') else: form = ResourceForm() return render_to_response("resources/resource_register.html",{'form':form, 'errors':errors},context_instance = RequestContext(request))