diff options
author | ngharo <nick@ngha.ro> | 2017-12-31 22:16:32 -0600 |
---|---|---|
committer | ngharo <nick@ngha.ro> | 2017-12-31 22:16:32 -0600 |
commit | f920c7da0618fd9f4181c2c78ef054e324185355 (patch) | |
tree | eba4a9f21fb8fd47e8a53f01e8a4dfae25a333e2 /server/buttonDispatcher.py | |
parent | 75d05326d067857d22474cc91d069003d7b64b17 (diff) | |
download | imOk-www-f920c7da0618fd9f4181c2c78ef054e324185355.tar.xz imOk-www-f920c7da0618fd9f4181c2c78ef054e324185355.zip |
Makefile: compile Babel and Sass source files to index.*
Diffstat (limited to 'server/buttonDispatcher.py')
-rw-r--r-- | server/buttonDispatcher.py | 44 |
1 files changed, 24 insertions, 20 deletions
diff --git a/server/buttonDispatcher.py b/server/buttonDispatcher.py index 59672d6..8938288 100644 --- a/server/buttonDispatcher.py +++ b/server/buttonDispatcher.py @@ -8,38 +8,26 @@ from lib import uuid @cherrypy.expose class ButtonDispatcher(Dispatcher): + @cherrypy.tools.json_out() def GET(self, id=None): # GET /button - return all buttons if id is None: - return self.response(loadAll()) + return loadAll() # GET /button/{id} - return single button self.validate_uuid(id) button = Button() - return self.response(button.loadById(id).toJSON()) + return button.loadById(id).toDict() - def POST(self, id, status): - # POST /button/{id}?status={} - updates button status - self.validate_uuid(id) - - button = Button() - button.loadById(id) - - cherrypy.log("Updating status to " + str(status)) - # TODO validate status - button.status = int(status) - button.save() - - return self.response(button.toJSON()) - - def PUT(self, id=None): + @cherrypy.tools.json_out() + def POST(self, id=None): button = Button() # PUT /button - creates button if id is None: button.id = uuid.gen() - return self.response(button.save().toJSON()) + return button.save().toDict() # PUT /button/{id} - presses button else: @@ -48,12 +36,28 @@ class ButtonDispatcher(Dispatcher): button.save() - return self.response(button.toJSON()) + return button.toDict() + + @cherrypy.tools.json_out() + def PUT(self, id, status): + # POST /button/{id}?status={} - updates button status + self.validate_uuid(id) + + button = Button() + button.loadById(id) + + cherrypy.log("Updating status to " + str(status)) + # TODO validate status + button.status = int(status) + button.save() + + return button.toDict() + @cherrypy.tools.json_out() def DELETE(self, id): # DELETE /button/{id} - deletes button button = Button() button.loadById(id) button.delete() - return self.response(True) + return True |