def order(request, form):
dajax = Dajax()
q=deserialize_form(form)
ttype = ''
if not q.get('buy-amount', None) is None: ttype = 'buy'
if not q.get('sale-amount', None) is None: ttype = 'sale'
form = OrdersForm(prefix=ttype, data=q)
if form.is_valid():
c=form.cleaned_data
user=request.user
if user.is_authenticated() and user.is_active:
pair, amount, rate = c.get('pair'), c.get('amount'), c.get('rate')
total, commission, pos = pair.calc(amount, rate, ttype)
if ttype == 'buy': pos = pair.right
if ttype == 'sale': pos = pair.left
valuta = pos.value
balance = user.orders_balance(valuta)
if ttype == 'buy': _sum = balance - total
if ttype == 'sale': _sum = balance - amount
if _sum >= 0:
_ret = getattr(pair, "order_%s" % ttype)(user, amount, rate)
dajax.remove_css_class('#{type}_form input'.format(**{"type":ttype}), 'error')
dajax.script("location.reload();")
else:
text = "????? ?????? ????????? ??? ?????? ?? {sum} {valuta}".format(**{"sum":floatformat(-_sum, -8), "valuta": pos })
dajax.script("$('#info_{type}').text('{text}');".format(**{"type":ttype, "text":text, }))
else:
pair, amount, rate = c.get('pair'), c.get('amount'), c.get('rate')
total, commission, pos = pair.calc(amount, rate, ttype)
if ttype == 'buy': _sum = total
if ttype == 'sale': _sum = amount
text = "????? ?????? ????????? ??? ?????? ?? {sum} {valuta}".format(**{"sum":floatformat(-_sum, -8), "valuta": pos })
dajax.script("$('#info_{type}').text('{text}');".format(**{"type":ttype, "text":text, }))
else:
dajax.script("$('#info_{type}').text('{text}');".format(**{"type":ttype, "text":"??????????? ????????? ???? ?? ?????.", }))
for error in form.errors:
dajax.add_css_class('#id_%s-%s' % (ttype, error), 'error')
return dajax.json()
评论列表
文章目录