RIA con Python...
Juan M.
juatman_2000 en yahoo.es
Jue Ago 30 23:54:09 CEST 2007
Hola :-)
Buscando información y trasteando he conseguido desarrollar el ejemplo RIA
(Rich Internet Application) de "mini-calculadora" para CherryPy2.2.1; así
que funciona bien en TurboGears 1.
RIA, RIA con Python. :-))
He aquí el código; espero que os sea útil, saludos.
_____________________________________________________________________________________
import cherrypy
page = \
"""<html>
<head>
<script type="text/javascript">
function update() {
var x = document.getElementById('x');
var y = document.getElementById('y');
var z = document.getElementById('z');
var req3 = new XMLHttpRequest();
req3.onreadystatechange = function () {
if(req3.readyState == 4 && req3.status == 200) {
z.innerHTML = req3.responseText;
z.value = req3.responseText;
}
};
var url = "/multip?x=" + x.value + ";y=" + y.value;
req3.open("GET", url, true);
req3.send(null);
var req1 = new XMLHttpRequest();
req1.onreadystatechange = function () {
if(req1.readyState == 4 && req1.status == 200) {
diva.innerHTML = req1.responseText;
}
};
</script>
</head>
<body>
<input type="text" name="x" id="x" value="2" size="3">
*
<input type="text" name="y" id="y" value="3" size="3">
=
<input type="text" name="z" id="z" value="" size="3">
<input type="button" name="check" value="Calculate" onclick="update();
return false;">
</body>
</html>
"""
class Test(object):
@cherrypy.expose
def index(self):
return page
@cherrypy.expose
def multip(self, x,y):
try:
float_x, float_y = float(x), float(y)
except:
return 0
return str(float_x * float_y)
cherrypy.tree.mount(Test())
cherrypy.config.update({'log_debug_info_filter.on':False})
cherrypy.server.start()
Más información sobre la lista de distribución Python-es