def create_order(request, secret, user, partner_id_str, promise_id_str, tmpl='xhtml-mp/create_order.html', method=None): partner_id = int(partner_id_str) promise_id = int(promise_id_str) method = method or request.GET.get('method') or request.method if method == 'POST': form = CreateOrderForm(request.POST) if form.is_valid(): request._cmbarter_trx_cost += 8.0 order_id = db.insert_delivery_order( user['trader_id'], partner_id, promise_id, form.cleaned_data['amount'], form.cleaned_data['carrier'], form.cleaned_data['instruction']) if order_id: return show_my_order(request, secret, order_id, method='GET') else: form.avl_amount = db.get_deposit_avl_amount( user['trader_id'], partner_id, promise_id) form.show_avl_amount = form.avl_amount < form.cleaned_data[ 'amount'] form.insufficient_amount = True else: form = CreateOrderForm() # Get partner's name. trust = db.get_trust(user['trader_id'], partner_id) if not trust: raise Http404 # Get product's information. product = db.get_product(partner_id, promise_id) if not product: raise Http404 # Truncate form.avl_amount if hasattr(form, 'avl_amount'): form.avl_amount = utils.truncate(form.avl_amount, product['epsilon']) # Render everything. c = { 'settings': settings, 'secret': secret, 'user': user, 'trust': trust, 'product': product, 'form': form } return render(request, tmpl, c)
def create_order(request, user, partner_id_str, promise_id_str, tmpl='create_order.html'): partner_id = int(partner_id_str) promise_id = int(promise_id_str) if request.method == 'POST': form = forms.CreateOrderForm(request.POST) if form.is_valid(): request._cmbarter_trx_cost += 8.0 order_id = db.insert_delivery_order( user['trader_id'], partner_id, promise_id, form.cleaned_data['amount'], form.cleaned_data['carrier'], form.cleaned_data['instruction']) if order_id: return HttpResponseRedirect(reverse( show_my_order, args=[user['trader_id'], order_id])) else: form.avl_amount = db.get_deposit_avl_amount(user['trader_id'], partner_id, promise_id) form.show_avl_amount = form.avl_amount < form.cleaned_data['amount'] form.insufficient_amount = True else: form = forms.CreateOrderForm() # Get partner's name. trust = db.get_trust(user['trader_id'], partner_id) if not trust: raise Http404 # Get product's information. product = db.get_product(partner_id, promise_id) if not product: raise Http404 # Get user's list of partners. partners = db.get_trust_list(user['trader_id']) # Truncate form.avl_amount if hasattr(form, 'avl_amount'): form.avl_amount = utils.truncate(form.avl_amount, product['epsilon']) # Render everything adding CSRF protection. c = {'settings': settings, 'user': user, 'trust': trust, 'product': product, 'partners': partners, 'form': form } c.update(csrf(request)) return render_to_response(tmpl, c)
def make_withdrawal(request, user, customer_id_str, promise_id_str, tmpl='make_withdrawal.html'): customer_id = int(customer_id_str) promise_id = int(promise_id_str) if request.method == 'POST': form = forms.MakeWithdrawalForm(request.POST) if form.is_valid(): request._cmbarter_trx_cost += 12.0 if db.insert_transaction( user['trader_id'], customer_id, promise_id, (- form.cleaned_data['amount']), form.cleaned_data['reason'], False, None, None, None, None, None): return HttpResponseRedirect("%s?%s" % ( reverse(report_transaction_commit, args=[user['trader_id']]), urllib.urlencode({'backref': request.GET.get('backref', u'/')}) )) else: form.insufficient_amount = True else: form = forms.MakeWithdrawalForm(initial={ 'amount': request.GET.get('amount'), 'reason': request.GET.get('reason')}) # Get customer's profile request._cmbarter_trx_cost += 1.0 trader = db.get_profile(customer_id) # Get product's information. product = db.get_product(user['trader_id'], promise_id) if trader and product: # Get the maximum withdrawable amount and put it in the form's help-text. l = db.get_deposit(customer_id, user['trader_id'], promise_id) max_amount = utils.truncate(l['amount'] if l else 0.0, product['epsilon']) form.fields['amount'].help_text = _("may not exceed %(amount)s") % {'amount': max_amount } # Render everything adding CSRF protection. c = {'settings': settings, 'user' : user, 'trader': trader, 'product': product, 'form' : form } c.update(csrf(request)) return render_to_response(tmpl, c) return HttpResponseRedirect(reverse( 'products-unknown-product', args=[user['trader_id'], user['trader_id']]))
def make_withdrawal(request, secret, user, customer_id_str, promise_id_str, tmpl='xhtml-mp/make_withdrawal.html', method=None): customer_id = int(customer_id_str) promise_id = int(promise_id_str) method = method or request.GET.get('method') or request.method if method == 'POST': form = MakeWithdrawalForm(request.POST) if form.is_valid(): request._cmbarter_trx_cost += 12.0 if db.insert_transaction( user['trader_id'], customer_id, promise_id, (- form.cleaned_data['amount']), form.cleaned_data['reason'], False, None, None, None, None, None): return report_transaction_commit( request, secret, method='GET', backref=request.GET.get('backref', u'/mobile/')) else: form.insufficient_amount = True else: form = MakeWithdrawalForm(initial={ 'amount': request.GET.get('amount'), 'reason': request.GET.get('reason')}) # Get customer's profile request._cmbarter_trx_cost += 1.0 trader = db.get_profile(customer_id) # Get product's information. product = db.get_product(user['trader_id'], promise_id) if trader and product: # Get the maximum withdrawable amount and put it in the form's help-text. l = db.get_deposit(customer_id, user['trader_id'], promise_id) max_amount = utils.truncate(l['amount'] if l else 0.0, product['epsilon']) form.fields['amount'].help_text = _("may not exceed %(amount)s") % {'amount': max_amount } # Render everything. c = {'settings': settings, 'user' : user, 'secret': secret, 'trader': trader, 'product': product, 'form' : form, 'max_amount': max_amount } return render(request, tmpl, c) return show_unknown_product(request, secret, user['trader_id'])
def create_order(request, secret, user, partner_id_str, promise_id_str, tmpl='xhtml-mp/create_order.html', method=None): partner_id = int(partner_id_str) promise_id = int(promise_id_str) method = method or request.GET.get('method') or request.method if method == 'POST': form = CreateOrderForm(request.POST) if form.is_valid(): request._cmbarter_trx_cost += 8.0 order_id = db.insert_delivery_order( user['trader_id'], partner_id, promise_id, form.cleaned_data['amount'], form.cleaned_data['carrier'], form.cleaned_data['instruction']) if order_id: return show_my_order(request, secret, order_id, method='GET') else: form.avl_amount = db.get_deposit_avl_amount(user['trader_id'], partner_id, promise_id) form.show_avl_amount = form.avl_amount < form.cleaned_data['amount'] form.insufficient_amount = True else: form = CreateOrderForm() # Get partner's name. trust = db.get_trust(user['trader_id'], partner_id) if not trust: raise Http404 # Get product's information. product = db.get_product(partner_id, promise_id) if not product: raise Http404 # Truncate form.avl_amount if hasattr(form, 'avl_amount'): form.avl_amount = utils.truncate(form.avl_amount, product['epsilon']) # Render everything. c = {'settings': settings, 'secret': secret, 'user': user, 'trust': trust, 'product': product, 'form': form } return render(request, tmpl, c)
def make_withdrawal(request, secret, user, customer_id_str, promise_id_str, tmpl='xhtml-mp/make_withdrawal.html', method=None): customer_id = int(customer_id_str) promise_id = int(promise_id_str) method = method or request.GET.get('method') or request.method if method == 'POST': form = MakeWithdrawalForm(request.POST) if form.is_valid(): request._cmbarter_trx_cost += 12.0 if db.insert_transaction(user['trader_id'], customer_id, promise_id, (-form.cleaned_data['amount']), form.cleaned_data['reason'], False, None, None, None, None, None): return report_transaction_commit(request, secret, method='GET', backref=request.GET.get( 'backref', u'/mobile/')) else: form.insufficient_amount = True else: form = MakeWithdrawalForm( initial={ 'amount': request.GET.get('amount'), 'reason': request.GET.get('reason') }) # Get customer's profile request._cmbarter_trx_cost += 1.0 trader = db.get_profile(customer_id) # Get product's information. product = db.get_product(user['trader_id'], promise_id) if trader and product: # Get the maximum withdrawable amount and put it in the form's help-text. l = db.get_deposit(customer_id, user['trader_id'], promise_id) max_amount = utils.truncate(l['amount'] if l else 0.0, product['epsilon']) form.fields['amount'].help_text = _("may not exceed %(amount)s") % { 'amount': max_amount } # Render everything. c = { 'settings': settings, 'user': user, 'secret': secret, 'trader': trader, 'product': product, 'form': form, 'max_amount': max_amount } return render(request, tmpl, c) return show_unknown_product(request, secret, user['trader_id'])
def truncate_abs_amount(amount, epsilon): return truncate(abs(amount), epsilon)
def truncate_amount_for_url(amount, epsilon, negate=False): tamt = truncate(-amount if negate else amount, epsilon) return unicode(tamt).replace('+', '')
def truncate_amount(amount, epsilon, negate=False): return truncate(-amount if negate else amount, epsilon)