Ejemplo n.º 1
0
def market_index(request, pk):
    
    market_id = int(pk)
    mkt = get_object_or_404(Market, id=market_id)
    acc = mkt.primary_account(request.user)

    if request.method == 'POST' and acc != None:
        # user wants to post a bid
        form = MarketForm(mkt, acc, post=request.POST) # Bind data from request.POST into a form

        # parse the position from the POST data
        form.position = mkt.parse_bid(request.POST)

        # place the order
        ord = acc.place_order(mkt, form.position)
        # adds the newly created order to the form before displaying it. 
        # ONLY if the order was successfully created (i.e. non-empty)
        if ord:
            form.orders.append(ord.get_data(form.outcomes))
    else:   # just display the market page
        form = MarketForm(mkt, acc)

 
    return render(request, 'market/index.html', {
        'form': form,
        })
Ejemplo n.º 2
0
def createMarket(request, idEvent):
	form2 = LoginForm()
	title="non"
	event=Event.objects.get(id=idEvent)
	markets=Market.objects.filter(event=event)
	if request.method == "POST":
		mform = MarketForm(request.POST)
		if mform.is_valid():
			#for i in range(0, event.nbMarkets):
			market=Market()
			market.event=event
			#market.outcome = mform.cleaned_data['outcome_%i' % i]
			market.outcome = mform.cleaned_data['outcome']
			market.save()
			mform = MarketForm()	
		return render(request, 'markets/createMarket.html', locals())	
	else:
		mform = MarketForm()	
		return render(request, 'markets/createMarket.html', locals())