Commits

tuck committed c588928

evol

Comments (0)

Files changed (5)

 pyramid.debug_routematch = false
 pyramid.debug_templates = true
 pyramid.default_locale_name = en
-#pyramid.includes = pyramid_debugtoolbar
-#                   pyramid_tm
+
+pyramid.includes = pyramid_debugtoolbar
+                   pyramid_tm
 
 sqlalchemy.url = sqlite:///%(here)s/MyIOTest.db
 
 session.secret = mysecret
 session.cookie_on_exception = true
 
+mako.directories = myiotest:templates
+
 [server:main]
 use = egg:Paste#http
 host = 0.0.0.0

myiotest/templates/index.mako

+<html>
+    <head>
+        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
+        <script>
+            $(function() {
+    ws = new WebSocket("ws://${host}:${port}/jobs/1");
+    ws.onmessage = function(msg) {
+        $("body").append("<p>" + msg.data + "</p>");
+    };
+    STARTED = false;
+    $("#start-stop").click(function(evt) {
+        $.post("/jobs/1", {state: STARTED ? "stop" : "start"}, function(result) {
+            STARTED = !STARTED;
+            $('#start-stop span').text(STARTED ? "on" : "off");
+
+        });
+    });
+});
+        </script>
+    </head>
+    <body>
+        <h1>Hi</h1>
+        <button id="start-stop">Job 1 <span>off</span></button>
+    </body>
+</html>

myiotest/views.py

 from myiotest.models import MyModel
 from pyramid.view import view_config
 from pyramid.response import Response
+from pyramid.settings import get_settings
 
 import eventlet
 from eventlet import wsgi
 from pyramid.view import view_config
 from stargate import WebSocketAwareResource, WebSocketView, is_websocket
 
-host = "127.0.0.1"
-port = 9998
-
-##    ws = new WebSocket("ws://%(host)s:%(port)s/jobs/1/");
-##        $.post("/jobs/1/", {state: STARTED ? "stop" : "start"}, function(result) {
-
-home_html = """\
-<html>
-    <head>
-        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
-        <script>
-            $(function() {
-    ws = new WebSocket("ws://%(host)s:%(port)s/jobs/1");
-    ws.onmessage = function(msg) {
-        $("body").append("<p>" + msg.data + "</p>");
-    };
-    STARTED = false;
-    $("#start-stop").click(function(evt) {
-        $.post("/jobs/1", {state: STARTED ? "stop" : "start"}, function(result) {
-            STARTED = !STARTED;
-            $('#start-stop span').text(STARTED ? "on" : "off");
-
-        });
-    });
-});
-        </script>
-    </head>
-    <body>
-        <h1>Hi</h1>
-        <button id="start-stop">Job 1 <span>off</span></button>
-    </body>
-</html>
-""" % dict(host=host, port=port)
 
 class JobRoot(object):
     """A container for jobs
 
     def __init__(self):
         pass
-        # super(Root, self).__init__(jobs=JobRoot())
-        # super(Root, self).__init__(jobs=myJobRoot)
 
-@view_config(route_name='home', context=Root)
+@view_config(route_name='home', context=Root, renderer='/index.mako')
 def home(context, request):
     """Serves up home_html, setting up a simple js demo"""
-    return Response(home_html)
+    settings = get_settings()
+    print settings
+    port = request.server_port
+    host = request.server_name
+    return {u'host':host,u'port':port}

myiotest/views.pyc

Binary file modified.