From 15741f838323097f00dc8090b81ff55def49f15b Mon Sep 17 00:00:00 2001 From: Caner Candan <candan@info.univ-angers.fr> Date: Fri, 24 Jan 2014 22:26:00 +0100 Subject: [PATCH] * added division in history page + finished transfer page --- static/favicon.ico | Bin 0 -> 1406 bytes templates/_messages.html | 26 +++++++++++++----------- templates/base.html | 9 ++++---- templates/wallets/history.html | 23 ++++++++++++++------- templates/wallets/transfer.html | 13 ++++++++---- webclient.py | 35 +++++++++++++++++++++++++++----- 6 files changed, 74 insertions(+), 32 deletions(-) create mode 100644 static/favicon.ico diff --git a/static/favicon.ico b/static/favicon.ico new file mode 100644 index 0000000000000000000000000000000000000000..895fc96a76b68b4924f1c51d022e1b82fa0f461f GIT binary patch literal 1406 zcmZQzU<5(|0R}M0U}azs1F|%L7$l?s#Ec9aKoZP=&}i&OouUjIY8@C}uZw4x5z5N2 zvEG^C^vXtt_xtJ?p3O32c(KTx;lsgZhW%5M85Sf<F+87R!>}k-mf`L80)|7ga~M{a znlL=>m1Q`#uoPkbC~GtXMnhnDh5$DU1D6mx+;2QAKt3ZQFH}H~1y~00GcqzVg9QXw z_<%(a7y$V|wJgF=E>MgE#Aid|14}IyCM5MhEnxFF;pTzOK(>#80puP=gnOXwAd33` mpMe2}f66m3eB@_fcnmb^7!b1nO#opK8zcsj1F3<j2hjko`!&q~ literal 0 HcmV?d00001 diff --git a/templates/_messages.html b/templates/_messages.html index 4c3e9c5f..beb5b215 100644 --- a/templates/_messages.html +++ b/templates/_messages.html @@ -1,12 +1,14 @@ -{% if messages %} - <div class="row"> - <div class="span12"> - {% for message in messages %} - <div class="alert alert-{% if message.tags == 'error' %}danger{% else %}{{message.tags}}{% endif %} fade in"> - <a class="close" title="Close" href="#" data-dismiss="alert">×</a> - <strong>{{message.tags|title}}:</strong> {{message}} - </div> - {% endfor %} - </div><!-- end span --> - </div><!-- end row --> -{% endif %} +{% with messages=get_flashed_messages(with_categories=true) %} + {% if messages %} + <div class="row"> + <div class="span12"> + {% for category, message in messages %} + <div class="alert alert-{% if category == 'error' %}danger{% else %}{{category}}{% endif %} fade in"> + <a class="close" title="Close" href="#" data-dismiss="alert">×</a> + <strong>{{category|title}}:</strong> {{message}} + </div> + {% endfor %} + </div><!-- end span --> + </div><!-- end row --> + {% endif %} +{% endwith %} diff --git a/templates/base.html b/templates/base.html index c198fc77..721fc035 100644 --- a/templates/base.html +++ b/templates/base.html @@ -1,12 +1,13 @@ <!DOCTYPE html> <html lang="en"> <head> - <meta charset="utf-8" /> + <meta charset="utf-8"/> <title>{% block page_title %}uCoin - {% block section_title %}{% endblock %}{% endblock %}</title> - <meta name="viewport" content="width=device-width, initial-scale=1.0"> + <meta name="viewport" content="width=device-width, initial-scale=1.0"/> <!-- Bootstrap --> - <link href="{{ url_for('static', filename='bootstrap/css/bootstrap.min.css') }}" rel="stylesheet" media="screen"> - <link href="{{ url_for('static', filename='bootstrap/css/bootstrap-theme.min.css') }}" rel="stylesheet" media="screen"> + <link href="{{ url_for('static', filename='bootstrap/css/bootstrap.min.css') }}" rel="stylesheet" media="screen"/> + <link href="{{ url_for('static', filename='bootstrap/css/bootstrap-theme.min.css') }}" rel="stylesheet" media="screen"/> + <link rel="shortcut icon" href="{{ url_for('static', filename='favicon.ico') }}"/> <style>body {overflow-y: scroll;}</style> <script type="text/javascript"> diff --git a/templates/wallets/history.html b/templates/wallets/history.html index aac5c318..78122b95 100644 --- a/templates/wallets/history.html +++ b/templates/wallets/history.html @@ -16,9 +16,18 @@ {% endwith %} <div class="col-md-7"> <ul class="nav nav-tabs pull-right"> - {% for name, color in [("all", "default"), ("transfer", "info"), ("issuance", "success"), ("fusion", "warning")] -%} - <li {% if type == name %}class="active"{% endif %}><a href="{{ url_for('wallet_history', pgp_fingerprint=key.fingerprint, type=name) }}"><span class="label label-{{color}}">{{name|title}}</span></a></li> + {% for name, color in [("all", "default"), ("transfer", "info"), ("issuance", "success"), ("fusion", "warning"), ("division", "danger")] -%} + <li {% if type == name %}class="active"{% endif %}> + <a href="{{ url_for('wallet_history', pgp_fingerprint=key.fingerprint, type=name) }}"> + <span class="label label-{{color}}">{{name|title}}</span> + </a> + </li> {% endfor -%} + <li> + <a href="{{ url_for('wallet_history_refresh', pgp_fingerprint=key.fingerprint, type=type) }}"> + <i class="glyphicon glyphicon-refresh"></i> + </a> + </li> </ul> </div> </div> @@ -36,10 +45,10 @@ </tr> </thead> <tbody> - {% for r in data -%} - {% with tx=r.value.transaction -%} + {% for number, tx in data.items()|reverse -%} + {# {% with tx=r.value.transaction -%} #} {% if type == "all" or tx.type|lower == type|lower -%} - <tr class="row1 {% if tx.type == 'TRANSFER' %}active{% elif tx.type == 'ISSUANCE' %}success{% else %}warning{% endif %}"> + <tr class="row1 {% if tx.type == 'TRANSFER' %}active{% elif tx.type == 'ISSUANCE' %}success{% elif tx.type == 'FUSION' %}warning{% else %}danger{% endif %}"> <td>{{tx.number}}</td> <td> @@ -57,7 +66,7 @@ </td> <td> - <span class="label label-{% if tx.type == 'TRANSFER' %}info{% elif tx.type == 'ISSUANCE' %}success{% else %}warning{% endif %}">{{tx.type|title}}</span> + <span class="label label-{% if tx.type == 'TRANSFER' %}info{% elif tx.type == 'ISSUANCE' %}success{% elif tx.type == 'FUSION' %}warning{% else %}danger{% endif %}">{{tx.type|title}}</span> <a class="tooltip_link" title="{{tx.comment|trim}}">{{tx.comment|trim|truncate(150)}}</a> </td> @@ -70,7 +79,7 @@ </td> </tr> {% endif -%} - {% endwith -%} + {# {% endwith -%} #} {% endfor -%} </tbody> </table> diff --git a/templates/wallets/transfer.html b/templates/wallets/transfer.html index 4789b701..06cbd34d 100644 --- a/templates/wallets/transfer.html +++ b/templates/wallets/transfer.html @@ -15,19 +15,17 @@ <div class="col-md-3"> <div class="alert alert-info tooltip_link" title="{{coins}}">Account balance: <span class="badge alert-default">{{clist.0}}</span></div> </div> - <div class="col-md-2"> + <div class="col-md-9"> <div class="alert alert-info">{{coins}}</div> </div> {% endwith -%} - <div class="col-md-7"> - </div> </div> <form role="form" method="post" action="{{ url_for('wallet_transfer', pgp_fingerprint=key.fingerprint) }}"> <div class="panel panel-success"> <div class="panel-heading"><h4>Recipient</h4></div> <div class="panel-body"> - <input class="typeahead" type="text" placeholder="Your recipient" name="recipient"/> + <input class="typeahead form-control" type="text" placeholder="Your recipient" name="recipient"/> </div> </div> @@ -49,6 +47,13 @@ </div> </div> + <div class="panel panel-success"> + <div class="panel-heading"><h4>Message</h4></div> + <div class="panel-body"> + <textarea class="form-control" name="message" placeholder="Write here a comment" rows="5"></textarea> + </div> + </div> + <div class="form-group"> <button class="btn btn-lg btn-primary btn-block" type="submit">Transfer</button> </div> diff --git a/webclient.py b/webclient.py index a9342f5e..8be2df7c 100755 --- a/webclient.py +++ b/webclient.py @@ -18,16 +18,22 @@ # from pprint import pprint -import ucoin, json, logging, argparse, sys, gnupg, hashlib, re, datetime as dt +import\ + ucoin, json, logging, argparse, sys,\ + gnupg, hashlib, re, datetime as dt from collections import OrderedDict from merkle import Merkle -from flask import Flask, request, render_template, jsonify +from flask import\ + Flask, request, render_template,\ + jsonify, redirect, abort, url_for,\ + flash from io import StringIO from werkzeug.contrib.cache import SimpleCache from itertools import combinations, chain logger = logging.getLogger("cli") app = Flask(__name__) +app.secret_key = 'some_secret' cache = SimpleCache() @app.template_filter('split') @@ -93,6 +99,9 @@ def get_sender_transactions(pgp_fingerprint): rv = cache.get(k) if rv is None: rv = list(ucoin.hdc.transactions.Sender(pgp_fingerprint).get()) + __dict = {} + for item in rv: __dict[item['value']['transaction']['number']] = item['value']['transaction'] + rv = __dict cache.set(k, rv, timeout=5*60) return rv @@ -101,6 +110,9 @@ def get_recipient_transactions(pgp_fingerprint): rv = cache.get(k) if rv is None: rv = list(ucoin.hdc.transactions.Recipient(pgp_fingerprint).get()) + __dict = {} + for item in rv: __dict[item['value']['transaction']['number']] = item['value']['transaction'] + rv = __dict cache.set(k, rv, timeout=5*60) return rv @@ -131,6 +143,14 @@ def wallet_history(pgp_fingerprint, type='all'): type=type, clist=clist(pgp_fingerprint)) +@app.route('/wallets/<pgp_fingerprint>/history/refresh') +@app.route('/wallets/<pgp_fingerprint>/history/refresh/<type>') +def wallet_history_refresh(pgp_fingerprint, type='all'): + k = 'sender_transactions_%s' % pgp_fingerprint; cache.set(k, None) + k = 'recipient_transactions_%s' % pgp_fingerprint; cache.set(k, None) + flash(u'History refreshed', 'info') + return redirect(url_for('wallet_history', pgp_fingerprint=pgp_fingerprint, type=type)) + def powerset(iterable): xs = list(iterable) return chain.from_iterable( combinations(xs,n) for n in range(len(xs)+1) ) @@ -245,9 +265,11 @@ def wallet_transfer(pgp_fingerprint): coins = cget(pgp_fingerprint, selected_combination) if not transfer(pgp_fingerprint, recipient, coins, message): - raise ValueError('transfer error') + flash(u'Transfer error', 'error') + else: + flash(u'Transfer success (%s %s)' % (str(selected_combination), recipient), 'success') - return '%s %s' % (str(selected_combination), recipient) + return redirect(url_for('wallet_transfer', pgp_fingerprint=pgp_fingerprint)) @app.route('/wallets/public_keys') def wallet_public_keys(): @@ -513,9 +535,12 @@ if __name__ == '__main__': def run(): print('Running...') + app.secret_key = ucoin.settings['secret_key'] app.run(debug=True) - subparsers.add_parser('run', help='Run the webclient').set_defaults(func=run) + sp = subparsers.add_parser('run', help='Run the webclient') + sp.add_argument('--secret_key', '-s', help='Pass a secret key used by the server for sessions', default='some_secret') + sp.set_defaults(func=run) args = parser.parse_args() -- GitLab