diff --git a/basicswap/http_server.py b/basicswap/http_server.py index f341594..214ec84 100644 --- a/basicswap/http_server.py +++ b/basicswap/http_server.py @@ -13,6 +13,8 @@ import threading import http.client import urllib.parse from http.server import BaseHTTPRequestHandler, HTTPServer +from jinja2 import Environment, FileSystemLoader + from .util import ( COIN, format8, @@ -33,6 +35,9 @@ from .basicswap import ( ABS_LOCK_TIME, ) +file_loader = FileSystemLoader('templates') +env = Environment(loader=file_loader) + def getCoinName(c): return chainparams[c]['name'].capitalize() @@ -484,23 +489,13 @@ class HttpHandler(BaseHTTPRequestHandler): swap_client = self.server.swap_client summary = swap_client.getSummary() - content = html_content_start(self.server.title, self.server.title, 30) \ - + '

View Wallets

' \ - + '

' \ - + 'Page Refresh: 30 seconds
' \ - + 'Network: ' + str(summary['network']) + '
' \ - + 'Swaps in progress: ' + str(summary['num_swapping']) + '
' \ - + 'Network Offers: ' + str(summary['num_network_offers']) + '
' \ - + 'Sent Offers: ' + str(summary['num_sent_offers']) + '
' \ - + 'Received Bids: ' + str(summary['num_recv_bids']) + '
' \ - + 'Sent Bids: ' + str(summary['num_sent_bids']) + '
' \ - + 'Watched Outputs: ' + str(summary['num_watched_outputs']) + '
' \ - + '

' \ - + '

' \ - + 'New Offer
' \ - + '

' - content += '' - return bytes(content, 'UTF-8') + template = env.get_template('index.html') + return bytes(template.render( + titil=self.server.title, + refresh=30, + h2=self.server.title, + summary=summary + ), 'UTF-8') def putHeaders(self, status_code, content_type): self.send_response(status_code) diff --git a/setup.py b/setup.py index f547cf9..d33d56a 100644 --- a/setup.py +++ b/setup.py @@ -27,6 +27,7 @@ setuptools.setup( "protobuf", "sqlalchemy", "python-gnupg", + "Jinja2", ], entry_points={ "console_scripts": [ diff --git a/templates/header.html b/templates/header.html new file mode 100644 index 0000000..d244993 --- /dev/null +++ b/templates/header.html @@ -0,0 +1,12 @@ + + + +{% if refresh %} + +{% endif %} +{{ title }} + + +{% if h2 %} +

{{ h2 }}

+{% endif %} diff --git a/templates/index.html b/templates/index.html new file mode 100644 index 0000000..40e87b8 --- /dev/null +++ b/templates/index.html @@ -0,0 +1,18 @@ +{% include 'header.html' %} + +

View Wallets

+ +

+Page Refresh: 30 seconds
+Swaps in progress: {{ summary.num_swapping }}
+Network Offers: {{ summary.num_network_offers }}
+Sent Offers: {{ summary.num_sent_offers }}
+Received Bids: {{ summary.num_recv_bids }}
+Sent Bids: {{ summary.num_sent_bids }}
+Watched Outputs: {{ summary.num_watched_outputs }}
+

+ +

New Offer

+ + + diff --git a/tests/test_prepare.py b/tests/test_prepare.py index 4e6acc7..757af95 100644 --- a/tests/test_prepare.py +++ b/tests/test_prepare.py @@ -67,7 +67,7 @@ class Test(unittest.TestCase): self.assertTrue(settings['chainclients']['namecoin']['connection_type'] == 'none') 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): prepareSystem.main() with open(config_path) as fs: