summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPiotr Dobrowolski <admin@tastycode.pl>2017-04-07 17:34:09 +0200
committerPiotr Dobrowolski <admin@tastycode.pl>2017-04-07 17:34:09 +0200
commit23370b41d9abd22ba82028f2b3a3832593e71acd (patch)
treeda2c9f646f0c93fc552d409b614d7b20b7b5f483
parent30b8bfbadae4dde9e3f6101ecc74dabe335c19d5 (diff)
downloadbitvend-23370b41d9abd22ba82028f2b3a3832593e71acd.tar.gz
bitvend-23370b41d9abd22ba82028f2b3a3832593e71acd.tar.bz2
bitvend-23370b41d9abd22ba82028f2b3a3832593e71acd.tar.xz
bitvend-23370b41d9abd22ba82028f2b3a3832593e71acd.zip
Templates cleanup, pagination, transactions list, hallofshame
-rw-r--r--bitvend/__init__.py7
-rw-r--r--bitvend/models.py2
-rw-r--r--bitvend/templates/_formathelpers.html13
-rw-r--r--bitvend/templates/_helpers.html (renamed from bitvend/templates/_formhelpers.html)41
-rw-r--r--bitvend/templates/base.html12
-rw-r--r--bitvend/templates/index.html15
-rw-r--r--bitvend/templates/transactions.html38
-rw-r--r--bitvend/views.py26
8 files changed, 114 insertions, 40 deletions
diff --git a/bitvend/__init__.py b/bitvend/__init__.py
index 8e4fb77..0696395 100644
--- a/bitvend/__init__.py
+++ b/bitvend/__init__.py
@@ -38,5 +38,10 @@ def create_app():
'proc_online': proc.online,
}
- return app
+ def url_for_other_page(page):
+ args = flask.request.view_args.copy()
+ args['page'] = page
+ return flask.url_for(flask.request.endpoint, **args)
+ app.jinja_env.globals['url_for_other_page'] = url_for_other_page
+ return app
diff --git a/bitvend/models.py b/bitvend/models.py
index bab5836..21a9891 100644
--- a/bitvend/models.py
+++ b/bitvend/models.py
@@ -27,7 +27,7 @@ class User(db.Model):
@balance.expression
def balance(self):
return (select([func.sum(Transaction.amount)]).
- where(Transaction.uid == cls.uid).
+ where(Transaction.uid == User.uid).
label("balance")
)
diff --git a/bitvend/templates/_formathelpers.html b/bitvend/templates/_formathelpers.html
deleted file mode 100644
index eafaf70..0000000
--- a/bitvend/templates/_formathelpers.html
+++ /dev/null
@@ -1,13 +0,0 @@
-{% macro format_currency(amount, color=True, precision=2) -%}
-{%- if amount == None -%}
-None
-{%- else -%}
-<span class="amount{% if amount < 0 and color %} amount-negative{% endif %}" data-original="{{ amount }}">
- {{ format_currency_raw(amount, precision) }}
-</span>
-{%- endif %}
-{%- endmacro %}
-
-{% macro format_currency_raw(amount, precision=0) -%}
-{{ ("%%.%sf" | format(precision) | format(amount/100)) }}SOG
-{%- endmacro %}
diff --git a/bitvend/templates/_formhelpers.html b/bitvend/templates/_helpers.html
index ac037cb..d0f7bcb 100644
--- a/bitvend/templates/_formhelpers.html
+++ b/bitvend/templates/_helpers.html
@@ -1,3 +1,16 @@
+{% macro format_currency(amount, color=True, precision=2) -%}
+{%- if amount == None -%}
+None
+{%- else -%}
+<span class="amount{% if amount < 0 and color %} amount-negative{% endif %}" data-original="{{ amount }}">
+ {{ format_currency_raw(amount, precision) }}
+</span>
+{%- endif %}
+{%- endmacro %}
+
+{% macro format_currency_raw(amount, precision=0) -%}
+{{ ("%%.%sf" | format(precision) | format(amount/100)) }}SOG
+{%- endmacro %}
{% macro render_field(field, prefix=None, suffix=None, layout=True, label=True) %}
{% if field.type == 'HiddenField' %}
{{ field(**kwargs) }}
@@ -56,3 +69,31 @@
</div>
{% endif %}
{% endmacro %}
+
+{% macro render_pagination(pagination) %}
+ <ul class="pagination text-center">
+ {% if pagination.has_prev %}
+ <li><a href="{{ url_for_other_page(pagination.page - 1) }}">&laquo;</a></li>
+ {% else %}
+ <li class="disabled"><a>&laquo;</a></li>
+ {% endif %}
+
+ {%- for page in pagination.iter_pages() %}
+ {% if page %}
+ {% if page != pagination.page %}
+ <li><a href="{{ url_for_other_page(page) }}">{{ page }}</a></li>
+ {% else %}
+ <li class="active"><a href="{{ url_for_other_page(page) }}">{{ page }}</a></li>
+ {% endif %}
+ {% else %}
+ <li class="disabled"><a>…</a></li>
+ {% endif %}
+ {%- endfor %}
+
+ {% if pagination.has_next %}
+ <li><a href="{{ url_for_other_page(pagination.page + 1) }}">&raquo;</a></li>
+ {% else %}
+ <li class="disabled"><a>&raquo;</a></li>
+ {% endif %}
+ </ul>
+{% endmacro %}
diff --git a/bitvend/templates/base.html b/bitvend/templates/base.html
index a79f270..692a419 100644
--- a/bitvend/templates/base.html
+++ b/bitvend/templates/base.html
@@ -50,16 +50,8 @@
</div>
<div class="navbar-collapse collapse" id="navbar-main">
<p class="navbar-text navbar-nav">
- {% if mdb_online %}
- <span class="label label-success">mdb: online</span>
- {% else %}
- <span class="label label-danger">mdb: offline</span>
- {% endif %}
- {% if proc_online %}
- <span class="label label-success">payments: online</span>
- {% else %}
- <span class="label label-danger">payments: offline</span>
- {% endif %}
+ <span class="label {% if mdb_online %}label-success{% else %}label-danger{% endif %}">mdb</span>
+ <span class="label {% if proc_online %}label-success{% else %}label-danger{% endif %}">bitcoin</span>
</p>
{% if current_user.is_authenticated %}
diff --git a/bitvend/templates/index.html b/bitvend/templates/index.html
index e66f9a4..afd89b3 100644
--- a/bitvend/templates/index.html
+++ b/bitvend/templates/index.html
@@ -1,7 +1,6 @@
{% extends "base.html" %}
-{% from "_formathelpers.html" import format_currency %}
-{% from "_formhelpers.html" import render_field, render_submit %}
+{% from "_helpers.html" import format_currency, render_field, render_submit %}
{% block content %}
{% if not mdb_online or not proc_online %}
@@ -47,6 +46,18 @@
</div>
</div>
</form>
+
+ <h3 class="page-header">Hall of Shame</h3>
+ <table class="table table-hover table-striped">
+ <thead><tr>
+ <th>Name</th><th>Balance</th>
+ </tr></thead>
+ {% for user in hallofshame %}
+ <tr><td>{{ user }}</td><td>{{ format_currency(user.balance) }}</td></tr>
+ {% else %}
+ <tr><td colspan=2 class="placeholder">Wow! Nobody's due!</td></tr>
+ {% endfor %}
+ </table>
</div>
<div class="col-sm-8">
<h3 class="page-header">Latest transactions</h3>
diff --git a/bitvend/templates/transactions.html b/bitvend/templates/transactions.html
new file mode 100644
index 0000000..7ee0a2f
--- /dev/null
+++ b/bitvend/templates/transactions.html
@@ -0,0 +1,38 @@
+{% extends "base.html" %}
+
+{% from "_helpers.html" import format_currency, render_pagination %}
+
+{% block content %}
+ <table class="table table-hover table-striped">
+ <thead>
+ <tr>
+ <th>Type</th>
+ <th>Amount</th>
+ <th>Date</th>
+ </tr>
+ </thead>
+
+ {% for tx in transactions.items %}
+ <tr{% if not tx.finished %} style="opacity: 0.5"{% endif %}>
+ <td>
+ {{ tx.type }} {% if not tx.finished %}<i>(processing)</i>{% endif %}
+ <small>
+ {% if tx.type == 'transfer' and tx.amount > 0 %}
+ from <b>{{ tx.related_user }}</b>
+ {% elif tx.type == 'transfer' and tx.amount < 0 %}
+ to <b>{{ tx.related }}</b>
+ {% elif tx.type == 'purchase' and tx.product_id %}
+ of product <b>{{ tx.product_id }}</b>
+ {% endif %}
+ </small>
+ </td>
+ <td>{{ format_currency(tx.amount) }}</td>
+ <td>{{ tx.created }}</td>
+ </tr>
+ {% else %}
+ <tr><td colspan=3 class="placeholder">Nothing to see here...</td></tr>
+ {% endfor %}
+ </table>
+
+ {{ render_pagination(transactions) }}
+{% endblock %}
diff --git a/bitvend/views.py b/bitvend/views.py
index 95b5dfe..f9b6920 100644
--- a/bitvend/views.py
+++ b/bitvend/views.py
@@ -17,6 +17,11 @@ bp = Blueprint('bitvend', __name__, template_folder='templates')
@bp.route('/')
def index():
transactions = []
+ hallofshame = User.query \
+ .order_by(User.balance.asc()) \
+ .filter(User.balance < 0) \
+ .limit(5) \
+ .all()
if current_user.is_authenticated:
transactions = current_user.transactions.order_by(Transaction.created.desc()).limit(10)
@@ -26,6 +31,14 @@ def index():
items=app.config['ITEMS'],
transactions=transactions,
transfer_form=TransferForm(),
+ hallofshame=hallofshame,
+ )
+
+@bp.route('/transactions/', defaults={'page': 1})
+@bp.route('/transactions/p/<int:page>')
+def transactions(page):
+ return render_template('transactions.html',
+ transactions=current_user.transactions.paginate(page)
)
@bp.route('/transfer', methods=['GET', 'POST'])
@@ -100,19 +113,6 @@ def cancel():
return redirect(url_for('.index'))
-@bp.route('/reclaim/<tx_hash>')
-@login_required
-def reclaim(tx_hash):
- tx = Transaction.query.filter_by(tx_hash=tx_hash).first()
-
- if tx and tx.product_id is None:
- dev.begin_session(tx.value, tx_hash)
- dev.begin_session(tx.value, tx_hash)
- dev.begin_session(tx.value, tx_hash)
- return redirect('/log')
-
- abort(404)
-
@bp.route('/qrcode/<path:data>')
def qrcode_gen(data):
bio = six.BytesIO()