[IMP] hw_escpos, hw_proxy: improved status page appeareance, add a listing of connected devices to hardware status page

bzr revid: fva@openerp.com-20140326103230-ib1myl1rmipoynkn
This commit is contained in:
Frédéric van der Essen 2014-03-26 11:32:30 +01:00
parent 6aa0187ca3
commit 9e801815bf
2 changed files with 43 additions and 3 deletions

View File

@ -37,6 +37,7 @@ from openerp.tools.translate import _
_logger = logging.getLogger(__name__)
class EscposDriver(Thread):
def __init__(self):
Thread.__init__(self)
@ -46,6 +47,7 @@ class EscposDriver(Thread):
def connected_usb_devices(self):
connected = []
for device in supported_devices.device_list:
if usb.core.find(idVendor=device['vendor'], idProduct=device['product']) != None:
connected.append(device)
@ -75,6 +77,8 @@ class EscposDriver(Thread):
self.push_task('status')
return self.status
def open_cashbox(self,printer):
printer.cashdraw(2)
printer.cashdraw(5)

View File

@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
import logging
import commands
import simplejson
import os
import os.path
@ -43,7 +44,32 @@ class Proxy(http.Controller):
@http.route('/hw_proxy/status', type='http', auth='none', cors='*')
def status_http(self):
resp = '<html>\n<body>\n<h1>Hardware Proxy Status</h1>\n'
resp = """
<!DOCTYPE HTML>
<html>
<head>
<title>OpenERP's PosBox</title>
<style>
body {
width: 480px;
margin: 60px auto;
font-family: sans-serif;
text-align: justify;
color: #6B6B6B;
}
.device {
border-bottom: solid 1px rgb(216,216,216);
padding: 9px;
}
.device:nth-child(2n) {
background:rgb(240,240,240);
}
</style>
</head>
<body>
<h1>Hardware Status</h1>
<p>The list of enabled drivers and their status</p>
"""
statuses = self.get_status()
for driver in statuses:
@ -56,12 +82,22 @@ class Proxy(http.Controller):
else:
color = 'red'
resp += "<h2 style='color:"+color+";'>"+driver+' : '+status['status']+"</h2>\n"
resp += "<h3 style='color:"+color+";'>"+driver+' : '+status['status']+"</h3>\n"
resp += "<ul>\n"
for msg in status['messages']:
resp += '<li>'+msg+'</li>\n'
resp += "</ul>\n"
resp += "<script>\n\tsetTimeout(function(){window.location.reload();},30000);\n</script>\n</body>\n</html>\n\n"
resp += """
<h2>Connected Devices</h2>
<p>The list of connected USB devices as seen by the posbox</p>
"""
devices = commands.getoutput("lsusb").split('\n')
resp += "<div class='devices'>\n"
for device in devices:
device_name = device[device.find('ID')+2:]
resp+= "<div class='device' data-device='"+device+"'>"+device_name+"</div>\n"
resp += "</div>\n"
resp += "</body>\n</html>\n\n"
return request.make_response(resp,{
'Cache-Control': 'no-cache',