def child_addCommand(self, ctx): request = inevow.IRequest(ctx) log.warn("addCommand", request) if request.method != "POST": # there's a correct http status for this raise ValueError("addCommand only takes POST") # nevow has a better form than this, i hope request.content.seek(0) args = dict(url.unquerify(request.content.read())) cmd = self.cmdlog.addCommand(URIRef(args["uri"]), nowLiteral(), self.user) # accept: json for AJAX # this kind of stuff was not working on the url.here redirect: # request.received_headers['host'] = 'bigasterisk.com' # request.prepath = ['magma'] # request.setHost('bigasterisk.com', 80) message = self.addedCommandMessage(cmd) class Ret(rend.Page): def renderHTTP(self, ctx): req = inevow.IRequest(ctx) req.setHeader("Location", url.URL.fromString("http://bigasterisk.com/magma").add("added", cmd)) # req.setResponseCode(303) # this would be right for non-js browsers, but i don't know how to make the page jquery read my message and not follow the redir req.write(message.encode("utf8")) req.finish() return "" return Ret()
def buttonPress(self): """returns deferred""" print "go" cmd = self.cmdlog.addCommand( URIRef("http://bigasterisk.com/magma/cmd/garageDoor"), nowLiteral(), self.user) return getPage("http://slash:9050/garageDoorOpen", method="POST", headers={'User-Agent': 'magma'})
def child_addCommand(self, ctx): request = inevow.IRequest(ctx) log.warn("addCommand", request) if request.method != "POST": # there's a correct http status for this raise ValueError("addCommand only takes POST") # nevow has a better form than this, i hope request.content.seek(0) args = dict(url.unquerify(request.content.read())) cmd = self.cmdlog.addCommand(URIRef(args['uri']), nowLiteral(), self.user) # accept: json for AJAX # this kind of stuff was not working on the url.here redirect: #request.received_headers['host'] = 'bigasterisk.com' #request.prepath = ['magma'] #request.setHost('bigasterisk.com', 80) message = self.addedCommandMessage(cmd) class Ret(rend.Page): def renderHTTP(self, ctx): req = inevow.IRequest(ctx) req.setHeader( "Location", url.URL.fromString('http://bigasterisk.com/magma').add( 'added', cmd)) # req.setResponseCode(303) # this would be right for non-js browsers, but i don't know how to make the page jquery read my message and not follow the redir req.write(message.encode('utf8')) req.finish() return '' return Ret()
def buttonPress(self): """returns deferred""" print "go" cmd = self.cmdlog.addCommand(URIRef("http://bigasterisk.com/magma/cmd/garageDoor"), nowLiteral(), self.user) return getPage("http://slash:9050/garageDoorOpen", method="POST", headers={"User-Agent": "magma"})