summaryrefslogtreecommitdiff
path: root/ebus/web/controller.py
diff options
context:
space:
mode:
authoryvesf <yvesf@d0e8fea9-7529-0410-93fb-d39fd5b9c1dd>2010-06-09 18:13:33 +0000
committeryvesf <yvesf@d0e8fea9-7529-0410-93fb-d39fd5b9c1dd>2010-06-09 18:13:33 +0000
commit4b320a8d744b8efeb27c983bb6f08208ec743c29 (patch)
treeea400f4739f3eafeb6ea34d5e35bd943dab6d458 /ebus/web/controller.py
parentfeebdc2e14426921a585c31c5279886bca3e2eca (diff)
downloadebus-alt-4b320a8d744b8efeb27c983bb6f08208ec743c29.tar.gz
ebus-alt-4b320a8d744b8efeb27c983bb6f08208ec743c29.zip
blablabla
git-svn-id: http://10.2.2.13/svn/common/ebus@1677 d0e8fea9-7529-0410-93fb-d39fd5b9c1dd
Diffstat (limited to 'ebus/web/controller.py')
-rw-r--r--ebus/web/controller.py49
1 files changed, 36 insertions, 13 deletions
diff --git a/ebus/web/controller.py b/ebus/web/controller.py
index f3fa438..edf174d 100644
--- a/ebus/web/controller.py
+++ b/ebus/web/controller.py
@@ -1,11 +1,15 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
-import sys, os, time
-sys.path.insert(0,"lib")
-from itty import itty
+import os, time
+import itty
from werkzeug.contrib.cache import SimpleCache
from simplejson import dumps as dump_json
+from ebus.web import model
+
+
+def data(name):
+ return {"name":name}
"""
def data(name):
if name in (
@@ -74,25 +78,44 @@ def data(name):
return []
"""
+class CacheDecorator(object):
+ def __init__(self,key,timeout=20):
+ self.cache = SimpleCache(default_timeout=timeout)
+ self.func = None
+ self.key = key
+
+ def cachedFunc(self, *args, **kwargs):
+ key = self.key(args, kwargs)
+ ret = self.cache.get(key)
+ if ret is None:
+ ret = self.func(*args, **kwargs)
+ self.cache.set(key, ret)
+ return ret
+
+ def __call__(self, func):
+ self.func = func
+ return self.cachedFunc
@itty.get("/")
def index(req):
filename=os.path.join(os.path.dirname(__file__), "static", "index.html")
return open(filename,"r").read()
-json_cache = SimpleCache(default_timeout=20)
-@itty.get('/json/<name>')
-def json(req,name):
- value = json_cache.get(name)
- if value is None:
- value = deny.Response(dump_json(dict(map(lambda r: (r, {"label":r, "data":data(r)}), name.split(",")))), mimetype='application/json')
- json_cache.set(name, value)
- return value
+@itty.get('/json/(?P<name>[^/]+)')
+@itty.get('/json/(?P<name>[^/]+)/from_date/(?P<from_date>.+)')
+@CacheDecorator(key=lambda args,kwargs: tuple(kwargs.keys()) + tuple(kwargs.values()),
+ timeout=20)
+def json(req,name=None,from_date=None):
+ print "name=%s from_date=%s" % (name,from_date)
+ return itty.Response(dump_json( {"label":name, "data":data(name)} ),
+ content_type="application/json")
+
@itty.get("/static/(?P<filename>.+)")
def static(request,filename):
file = itty.static_file(filename, root=os.path.join(os.path.dirname(__file__), 'static'))
return itty.Response(file, content_type=itty.content_type(file))
-if __name__ == '__main__':
- sys.exit(itty.run_itty(host="0.0.0.0",port=5000))
+
+def run():
+ return itty.run_itty(host="0.0.0.0",port=5000)