diff options
author | Marcello Stanisci <marcello.stanisci@inria.fr> | 2016-11-18 11:32:58 +0100 |
---|---|---|
committer | Marcello Stanisci <marcello.stanisci@inria.fr> | 2016-11-18 11:32:58 +0100 |
commit | 1a39109a02f90dacbf3e85848a49a31c4ddb7afd (patch) | |
tree | 119f6dd3f69402ed6becbb6e60a4b8805b5079ca | |
parent | 2fb38799aa9e100dc0f97b67078b4012b1f7222f (diff) | |
download | bank-1a39109a02f90dacbf3e85848a49a31c4ddb7afd.tar.gz bank-1a39109a02f90dacbf3e85848a49a31c4ddb7afd.tar.bz2 bank-1a39109a02f90dacbf3e85848a49a31c4ddb7afd.zip |
Done with create-reserve
-rw-r--r-- | talerbank/app/amounts.py | 13 | ||||
-rw-r--r-- | talerbank/app/funds.py | 5 | ||||
-rw-r--r-- | talerbank/app/templates/home_page.html | 2 | ||||
-rw-r--r-- | talerbank/app/templates/profile_page.html | 32 | ||||
-rw-r--r-- | talerbank/app/views.py | 4 |
5 files changed, 37 insertions, 19 deletions
diff --git a/talerbank/app/amounts.py b/talerbank/app/amounts.py index 80bee24..19d0db2 100644 --- a/talerbank/app/amounts.py +++ b/talerbank/app/amounts.py @@ -15,7 +15,12 @@ # @author Marcello Stanisci from django.conf import settings +from .errors import BadAmount import re +import math +import logging + +logger = logging.getLogger(__name__) def floatify(amount_dict): return amount_dict['value'] + ( float(amount_dict['fraction']) / float(1000000)) @@ -29,18 +34,18 @@ def stringify_amount(amount_float): # use "x.00 CURRENCY" instead. def parse_amount(amount_str): - parsed = re.search('([0-9]+).([0-9]+) ([A-Z]+)', amount_str).search() + parsed = re.search('([0-9]+).([0-9]+) ([A-Z]+)', amount_str) if not parsed or len(str(parsed.group(2))) != settings.NDIGITS: - raise WrongAmountError(amount_str) + raise BadAmount(amount_str) # FIXME: check if settings.NDIGITS <= settings.FRACTION fraction_delta = settings.FRACTION / int(math.pow(10, len(str(parsed.group(2))))) - fraction = parsed.group(2) * fraction_delta + fraction = int(parsed.group(2)) * fraction_delta if parsed.group(3) != settings.TALER_CURRENCY: raise CurrencyMismatchError() return {'value': parsed.group(1), - 'fraction': fraction, + 'fraction': int(fraction), 'currency': parsed.group(3)} diff --git a/talerbank/app/funds.py b/talerbank/app/funds.py index 4748114..6bc09d9 100644 --- a/talerbank/app/funds.py +++ b/talerbank/app/funds.py @@ -19,12 +19,13 @@ from .errors import WrongMethod, BadWireDetails, CurrencyMismatch, NonExistentAc from . import amounts from .models import BankAccount, History from django.views.decorators.csrf import csrf_exempt -from django.http import JsonResponse +from django.http import JsonResponse, HttpResponse from django.shortcuts import render, redirect from django.http import HttpResponseServerError from django.contrib.auth.decorators import login_required from urllib.parse import urlparse, urljoin from django.conf import settings +from django.core.urlresolvers import reverse import requests import time import json @@ -80,7 +81,7 @@ def add_incoming(request): @login_required def withdraw_nojs(request): amount_str = request.POST['kudos_amount'] - response = HttpResponse(status_code=202) + response = HttpResponse(status=202) response['X-Taler-CallBack-Url'] = reverse('pin_tan') response['X-Taler-WtTypes'] = '["TEST"]' response['X-Taler-Amount'] = amounts.parse_amount(amount_str) diff --git a/talerbank/app/templates/home_page.html b/talerbank/app/templates/home_page.html index 4de2894..3ab02a3 100644 --- a/talerbank/app/templates/home_page.html +++ b/talerbank/app/templates/home_page.html @@ -34,7 +34,7 @@ <a href="{% url 'index' %}">JavaScript-less version!</a> {% else %} You are using the JavaScript-less version, try out the - <a href="{% url 'index' no_js='nojs'%}">JavaScript version!</a> + <a href="{% url 'index' use_js='use_js'%}">JavaScript version!</a> {% endif %} <br> <article> diff --git a/talerbank/app/templates/profile_page.html b/talerbank/app/templates/profile_page.html index 0f37800..7b4db1a 100644 --- a/talerbank/app/templates/profile_page.html +++ b/talerbank/app/templates/profile_page.html @@ -28,7 +28,9 @@ {% endif %} <link rel="stylesheet" type="text/css" href="{% static "disabled-button.css" %}"> <script src="{% static "chrome-store-link.js" %}" type="application/javascript"></script> - <script src="{% static "profile-page.js" %}" type="application/javascript"></script> + {% if use_js %} + <script src="{% static "profile-page.js" %}" type="application/javascript"></script> + {% endif %} {% endblock head %} {% block headermsg %} <h1 class="nav">Welcome <em>{{ name }}</em>!</h1> @@ -90,32 +92,40 @@ <div> <h2>Withdraw digital coins using Taler</h2> - {% if no_js %} - <form id="reserve-form" name="tform" action="{% url 'withdraw-nojs' %}"> - {% else %} - <form id="reserve-form" name="tform" action=""> - {% endif %} + <form id="reserve-form" + {% if use_js %} + action="" + {% else %} + action="{% url 'withdraw-nojs' %}" + method="post" + {% endif %} + name="tform"> {% csrf_token %} <!-- FIXME: This 'input' field seems not used, make sure it's not then remove it --> <input type="text" id="reserve-pk-input" name="reserve_pk" hidden></input> Amount to withdraw: <select id="reserve-amount" name="kudos_amount" autofocus> - {% if no_js %} + {% if use_js %} + <!-- programmatically filled --> + {% else %} + <!-- NOTE: the fractional part has to match settings.NDIGITS + FIXME: provide values programmatically --> <option value="1.00 {{ currency }}">1.00 {{ currency }}</option> <option value="10.00 {{ currency }}">10.00 {{ currency }}</option> <option value="15.00 {{ currency }}">15.00 {{ currency }}</option> <option value="20.00 {{ currency }}">20.00 {{ currency }}</option> - {% else %} - <!-- programmatically filled --> {% endif %} </select> <input type="text" name="mint_rcv" id="kudos-mint" hidden></input> <input id="select-exchange" class="taler-installed-show" - type="button" + {% if use_js %} + type="button" + {% else %} + type="submit" + {% endif %} value="Select exchange provider"></input> - <!-- fake disabled button, shown instead the real button when wallet not present --> <input class="taler-installed-hide" type="button" disabled diff --git a/talerbank/app/views.py b/talerbank/app/views.py index 9bca8a8..1d3b909 100644 --- a/talerbank/app/views.py +++ b/talerbank/app/views.py @@ -83,6 +83,7 @@ def profile_page(request, withdraw=False, registration=False): history = extract_history(user_account) logger.info(str(history)) reserve_pub = request.session.get('reserve_pub') + use_js = request.session.get('use_js') return render(request, 'profile_page.html', {'name': user_account.user.username, 'balance': stringify_amount(user_account.balance), 'currency': user_account.currency, @@ -91,4 +92,5 @@ def profile_page(request, withdraw=False, registration=False): 'history': history, 'withdraw': withdraw, 'registration': registration, - 'reserve_pub': reserve_pub}) + 'reserve_pub': reserve_pub, + 'use_js': use_js}) |