From 7a8c0ed9f212d99d3f317f28c0396fa8574af546 Mon Sep 17 00:00:00 2001 From: tecnovert Date: Fri, 26 Jul 2019 15:26:20 +0200 Subject: [PATCH] html: templates for bids and offers pages. --- basicswap/http_server.py | 45 ++++++++++++--------------------- basicswap/templates/bids.html | 16 ++++++++++++ basicswap/templates/offers.html | 16 ++++++++++++ 3 files changed, 48 insertions(+), 29 deletions(-) create mode 100644 basicswap/templates/bids.html create mode 100644 basicswap/templates/offers.html diff --git a/basicswap/http_server.py b/basicswap/http_server.py index 55181b5..2fecd3a 100644 --- a/basicswap/http_server.py +++ b/basicswap/http_server.py @@ -290,22 +290,14 @@ class HttpHandler(BaseHTTPRequestHandler): swap_client = self.server.swap_client offers = swap_client.listOffers(sent) - content = html_content_start(self.server.title, self.server.title) \ - + '

' + ('Sent ' if sent else '') + 'Offers

' - - content += '' - content += '' - for o in offers: - coin_from_name = getCoinName(Coins(o.coin_from)) - coin_to_name = getCoinName(Coins(o.coin_to)) - amount_to = (o.amount_from * o.rate) // COIN - content += ''.format( - time.strftime('%Y-%m-%d %H:%M', time.localtime(o.created_at)), - o.offer_id.hex(), coin_from_name, coin_to_name, format8(o.amount_from), format8(amount_to), format8(o.rate)) - - content += '
AtOffer IDCoin FromCoin ToAmount FromAmount ToRate
{0}{1}{2}{3}{4}{5}{6}
' - content += '

home

' - return bytes(content, 'UTF-8') + template = env.get_template('offers.html') + return bytes(template.render( + title=self.server.title, + h2=self.server.title, + page_type='Sent' if sent else 'Received', + offers=[(time.strftime('%Y-%m-%d %H:%M', time.localtime(o.created_at)), + o.offer_id.hex(), getCoinName(Coins(o.coin_from)), getCoinName(Coins(o.coin_to)), format8(o.amount_from), format8((o.amount_from * o.rate) // COIN), format8(o.rate)) for o in offers], + ), 'UTF-8') def page_advance(self, url_split, post_string): assert(len(url_split) > 2), 'Bid ID not specified' @@ -452,19 +444,14 @@ class HttpHandler(BaseHTTPRequestHandler): swap_client = self.server.swap_client bids = swap_client.listBids(sent=sent) - content = html_content_start(self.server.title, self.server.title) \ - + '

' + ('Sent ' if sent else '') + 'Bids

' - - content += '' - content += '' - for b in bids: - content += ''.format( - time.strftime('%Y-%m-%d %H:%M', time.localtime(b.created_at)), - b.bid_id.hex(), b.offer_id.hex(), getBidState(b.state), getTxState(b.initiate_txn_state), getTxState(b.participate_txn_state)) - content += '
AtBid IDOffer IDBid StatusITX StatusPTX Status
{0}{1}{2}{3}{4}{5}
' - - content += '

home

' - return bytes(content, 'UTF-8') + template = env.get_template('bids.html') + return bytes(template.render( + title=self.server.title, + h2=self.server.title, + page_type='Sent' if sent else 'Received', + bids=[(time.strftime('%Y-%m-%d %H:%M', time.localtime(b.created_at)), + b.bid_id.hex(), b.offer_id.hex(), getBidState(b.state), getTxState(b.initiate_txn_state), getTxState(b.participate_txn_state)) for b in bids], + ), 'UTF-8') def page_watched(self, url_split, post_string): swap_client = self.server.swap_client diff --git a/basicswap/templates/bids.html b/basicswap/templates/bids.html new file mode 100644 index 0000000..68c27f8 --- /dev/null +++ b/basicswap/templates/bids.html @@ -0,0 +1,16 @@ +{% include 'header.html' %} + +

{{ page_type }} Bids

+{% if refresh %} +

Page Refresh: {{ refresh }} seconds

+{% endif %} + + + +{% for b in bids %} + +{% endfor %} +
AtBid IDOffer IDBid StatusITX StatusPTX Status
{{ b[0] }}{{ b[1] }}{{ b[2] }}{{ b[3] }}{{ b[4] }}{{ b[5] }}
+ +

home

+ diff --git a/basicswap/templates/offers.html b/basicswap/templates/offers.html new file mode 100644 index 0000000..11a821d --- /dev/null +++ b/basicswap/templates/offers.html @@ -0,0 +1,16 @@ +{% include 'header.html' %} + +

{{ page_type }} Offers

+{% if refresh %} +

Page Refresh: {{ refresh }} seconds

+{% endif %} + + + +{% for o in offers %} + +{% endfor %} +
AtOffer IDCoin FromCoin ToAmount FromAmount ToRate
{{ o[0] }}{{ o[1] }}{{ o[2] }}{{ o[3] }}{{ o[4] }}{{ o[5] }}{{ o[6] }}
+ +

home

+