コード例 #1
0
ファイル: views.py プロジェクト: jdonier/market0.3
def home(request):		
	from django.db import connection
	cursor = connection.cursor()
	titre="Home"
	form2 = LoginForm()
	if request.method == "POST" and request.user.is_authenticated():   
		trform = TransferForm(request.POST)
		if trform.is_valid():
			transfer=Transfer()
			transfer.trader=Trader.objects.get(user=request.user)
			transfer.type=trform.cleaned_data["type"]
			transfer.volume=trform.cleaned_data["volume"]
			transfer.save()			
			trform = TransferForm()	
			trform.non_field_errors="Transfer successful !"
		else:	
			trform = TransferForm()	
	else:	
		trform = TransferForm()
	marketPerf=[]
	for market in Market.objects.all():
		if market.event.status==0 and market.event.globalEvent.dateClose>timezone.now():
			tv=Market.objects.tradedVolume(market=market)			
			if tv==None:
				tv=0
			tv=float(Decimal(tv).quantize(Decimal('.01'), rounding=ROUND_DOWN))	
			marketPerf.append([market.id, tv])
	marketPerf.sort(key=lambda k: (k[1]), reverse=True)
	marketPerf=marketPerf[0:3]
	perfData=[]
	perfName=[]
	for mp in range(0,3):
		market=Market.objects.get(id=marketPerf[mp][0])
		marketId=marketPerf[mp][0]
		cursor.execute("SELECT price price, volume volume, side side, timestamp timestamp FROM markets_trade WHERE not nullTrade and market_id=%i ORDER BY timestamp DESC" % marketId)
		trades = dictfetchall(cursor)
		trades=trades[:20]
		graphData=[]
		i=20
		for trade in trades:
			i=i-1
			graphData.append([i,float(trade['price'])])#[trade['volume'], trade['price']])	
		perfData.append([mp, graphData])
		if mp==0:
			n0=market.outcome	
			id0=market.id		
		if mp==1:
			n1=market.outcome
			id1=market.id				
		if mp==2:
			n2=market.outcome
			id2=market.id				
	return render(request, 'markets/home.html', locals())
コード例 #2
0
ファイル: views.py プロジェクト: jdonier/market0.1
def home(request):	
	titre="Home"
	form2 = LoginForm()	
	if request.method == "POST" and request.user.is_authenticated:   
		trform = TransferForm(request.POST)
		if trform.is_valid():
			transfer=Transfer()
			transfer.trader=Trader.objects.get(user=request.user)
			transfer.type=trform.cleaned_data["type"]
			transfer.volume=trform.cleaned_data["volume"]
			transfer.save()			
			trform = TransferForm()	
			trform.non_field_errors="Transfer successful !"
		else:	
			trform = TransferForm()	
	else:	
		trform = TransferForm()			
	return render(request, 'markets/home.html', locals())
コード例 #3
0
ファイル: views.py プロジェクト: jdonier/market0.3
def signup(request):
	if request.method == "POST":   
		form = SignupForm(request.POST)
		if form.is_valid():
			try:
				code = Code.objects.get(code=form.cleaned_data['code'])
			except:
				code=''
			if code!='':
				if code.active==True:
					code.active=False
					code.save()
					user=User()
					user.username = form.cleaned_data['username']
					user.email = form.cleaned_data['email']
					user.set_password(form.cleaned_data['password'])
					user.save()
					trader=Trader(user=user)
					trader.save()
					transfer=Transfer()
					transfer.trader=trader
					transfer.type=1
					transfer.volume=100
					transfer.save()			
					user = authenticate(username=form.cleaned_data['username'], password=form.cleaned_data['password'])  #Nous vérifions si les données sont correctes
					login(request, user)
					#return redirect('posts.views.user', id_user=user.id)
					return redirect('markets.views.home')
				else:
					form.non_field_errors="Wrong code"
					form2 = LoginForm()
			else:
				form.non_field_errors="Wrong code"
				form2 = LoginForm()
	else:
		form2 = LoginForm()
		form = SignupForm()	
	return render(request, 'markets/signup.html', locals())