def put(self, switch): session = Session() data = session.query(Switch).filter_by(pin=switch).first() if data is None: raise tornado.web.HTTPError(404) data.description = self.get_argument("description") try: session.commit() except Exception as e: #log.exception(e) session.rollback() raise tornado.web.HTTPError(500)
def post(self): session = Session() try: switch = Switch() switch.pin = int(self.get_argument("pin")) switch.description = self.get_argument("description") session.add(switch) session.commit() except Exception as e: #log.exception(e) session.rollback() raise tornado.web.HTTPError(500)
def delete(self, switch): session = Session() data = session.query(Switch).filter_by(pin=switch).first() if data is None: raise tornado.web.HTTPError(404) try: session.delete(data) session.commit() except Exception as e: #log.exception(e) session.rollback() raise tornado.web.HTTPError(500)