mirror of
https://github.com/basicswap/basicswap.git
synced 2024-11-16 15:58:17 +00:00
html: Start migrating to Jinja2.
This commit is contained in:
parent
5d238149ce
commit
b920f926c1
5 changed files with 44 additions and 18 deletions
|
@ -13,6 +13,8 @@ import threading
|
||||||
import http.client
|
import http.client
|
||||||
import urllib.parse
|
import urllib.parse
|
||||||
from http.server import BaseHTTPRequestHandler, HTTPServer
|
from http.server import BaseHTTPRequestHandler, HTTPServer
|
||||||
|
from jinja2 import Environment, FileSystemLoader
|
||||||
|
|
||||||
from .util import (
|
from .util import (
|
||||||
COIN,
|
COIN,
|
||||||
format8,
|
format8,
|
||||||
|
@ -33,6 +35,9 @@ from .basicswap import (
|
||||||
ABS_LOCK_TIME,
|
ABS_LOCK_TIME,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
file_loader = FileSystemLoader('templates')
|
||||||
|
env = Environment(loader=file_loader)
|
||||||
|
|
||||||
|
|
||||||
def getCoinName(c):
|
def getCoinName(c):
|
||||||
return chainparams[c]['name'].capitalize()
|
return chainparams[c]['name'].capitalize()
|
||||||
|
@ -484,23 +489,13 @@ class HttpHandler(BaseHTTPRequestHandler):
|
||||||
swap_client = self.server.swap_client
|
swap_client = self.server.swap_client
|
||||||
summary = swap_client.getSummary()
|
summary = swap_client.getSummary()
|
||||||
|
|
||||||
content = html_content_start(self.server.title, self.server.title, 30) \
|
template = env.get_template('index.html')
|
||||||
+ '<p><a href="/wallets">View Wallets</a></p>' \
|
return bytes(template.render(
|
||||||
+ '<p>' \
|
titil=self.server.title,
|
||||||
+ 'Page Refresh: 30 seconds<br/>' \
|
refresh=30,
|
||||||
+ 'Network: ' + str(summary['network']) + '<br/>' \
|
h2=self.server.title,
|
||||||
+ '<a href="/active">Swaps in progress: ' + str(summary['num_swapping']) + '</a><br/>' \
|
summary=summary
|
||||||
+ '<a href="/offers">Network Offers: ' + str(summary['num_network_offers']) + '</a><br/>' \
|
), 'UTF-8')
|
||||||
+ '<a href="/sentoffers">Sent Offers: ' + str(summary['num_sent_offers']) + '</a><br/>' \
|
|
||||||
+ '<a href="/bids">Received Bids: ' + str(summary['num_recv_bids']) + '</a><br/>' \
|
|
||||||
+ '<a href="/sentbids">Sent Bids: ' + str(summary['num_sent_bids']) + '</a><br/>' \
|
|
||||||
+ '<a href="/watched">Watched Outputs: ' + str(summary['num_watched_outputs']) + '</a><br/>' \
|
|
||||||
+ '</p>' \
|
|
||||||
+ '<p>' \
|
|
||||||
+ '<a href="/newoffer">New Offer</a><br/>' \
|
|
||||||
+ '</p>'
|
|
||||||
content += '</body></html>'
|
|
||||||
return bytes(content, 'UTF-8')
|
|
||||||
|
|
||||||
def putHeaders(self, status_code, content_type):
|
def putHeaders(self, status_code, content_type):
|
||||||
self.send_response(status_code)
|
self.send_response(status_code)
|
||||||
|
|
1
setup.py
1
setup.py
|
@ -27,6 +27,7 @@ setuptools.setup(
|
||||||
"protobuf",
|
"protobuf",
|
||||||
"sqlalchemy",
|
"sqlalchemy",
|
||||||
"python-gnupg",
|
"python-gnupg",
|
||||||
|
"Jinja2",
|
||||||
],
|
],
|
||||||
entry_points={
|
entry_points={
|
||||||
"console_scripts": [
|
"console_scripts": [
|
||||||
|
|
12
templates/header.html
Normal file
12
templates/header.html
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
<!DOCTYPE html><html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
{% if refresh %}
|
||||||
|
<meta http-equiv="refresh" content="{{ refresh }}">
|
||||||
|
{% endif %}
|
||||||
|
<title>{{ title }}</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
{% if h2 %}
|
||||||
|
<h2>{{ h2 }}</h2>
|
||||||
|
{% endif %}
|
18
templates/index.html
Normal file
18
templates/index.html
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
{% include 'header.html' %}
|
||||||
|
|
||||||
|
<p><a href="/wallets">View Wallets</a></p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
Page Refresh: 30 seconds<br/>
|
||||||
|
<a href="/active">Swaps in progress: {{ summary.num_swapping }}</a><br/>
|
||||||
|
<a href="/offers">Network Offers: {{ summary.num_network_offers }}</a><br/>
|
||||||
|
<a href="/sentoffers">Sent Offers: {{ summary.num_sent_offers }}</a><br/>
|
||||||
|
<a href="/bids">Received Bids: {{ summary.num_recv_bids }}</a><br/>
|
||||||
|
<a href="/sentbids">Sent Bids: {{ summary.num_sent_bids }}</a><br/>
|
||||||
|
<a href="/watched">Watched Outputs: {{ summary.num_watched_outputs }}</a><br/>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p><a href="/newoffer">New Offer</a><br/></p>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
|
@ -67,7 +67,7 @@ class Test(unittest.TestCase):
|
||||||
self.assertTrue(settings['chainclients']['namecoin']['connection_type'] == 'none')
|
self.assertTrue(settings['chainclients']['namecoin']['connection_type'] == 'none')
|
||||||
|
|
||||||
logger.info('Test addcoin existing')
|
logger.info('Test addcoin existing')
|
||||||
testargs = ['basicswap-prepare', '-datadir=' + test_path, '-disablecoin=namecoin']
|
testargs = ['basicswap-prepare', '-datadir=' + test_path, '-addcoin=namecoin']
|
||||||
with patch.object(sys, 'argv', testargs):
|
with patch.object(sys, 'argv', testargs):
|
||||||
prepareSystem.main()
|
prepareSystem.main()
|
||||||
with open(config_path) as fs:
|
with open(config_path) as fs:
|
||||||
|
|
Loading…
Reference in a new issue