def edit(self, id=None): m=Model() try: print(" .. GET Edit Data (ID): " + id) res = m.find_by_id(id) self.success(message="connections, edit id: " + str(id), data=res) except Exception as e: self.error(message="connections, edit id: " + str(id) + "msg: " + str(e) , data=None)
def destroy(self, id=None): try: data_json = self.request.body print(" .. DELETE Data: ID:" + str(data_json)) m=Model() m.init_from_json(data_json) res = m.find_by_id(m.id) res.delete() self.success(message="connections, successfully deletd id: " + str(m.id), data=str(m.id), format="json") except Exception as e: self.error(message="connections, destroy id: " + str(e))
def create(self): try: data_json = self.request.body m=Model() m.init_from_json(data_json, simple_conversion=True) m.upsert() self.success(message="connections, successfully created " + str(m.id), data=m, format="json") except Exception as e: self.error(message="connections, error updating " + str(m.id) + "msg: " + str(e), data=m, format="json")
def update(self, id=None): data_json = self.request.body m=Model() res = m.find_by_id(id) res.init_from_json(data_json, simple_conversion=True) try: #res.tags= res.tags.split(",") res.upsert() self.success(message="connections, successfully updated " + str(res.id), data=res, format="json") except Exception as e: self.error(message="connections, error updating: " + str(m.id) + "msg: " + str(e), data=data_json, format="json")
def serverinfo(self, id): """ render the server info view for the connection with the given uuid """ r=Redisinfo() c=Connections() redis_conf=c.find(c.where("_uuid") == id) r.set_connection(redis_conf=redis_conf.to_dict()) print(json.dumps(r.db.info())) try: self.render("serverinfo.tmpl", connected=True, connection_id=id, info=r.db.info()) except: self.error(message="Could not connect to Redis DB", data=json.dumps(redis_conf))
def index(self, year=None): """ Example Method with class attached routing (see above "/" ) """ print(" Calling IndexHandler.index from handlers/shorties.py: parameter index: " + str(year)) conn = self.get_secure_cookie("redisui:current_connection", None) print(f"found existing connnection cookie: {str(conn)}") if conn: c=Connections() redis_conf=c.find(c.where("_uuid") == id) self.render("redisdash.tmpl", connected=True, connection_id=conn, connection=redis_conf) else: #self.set_secure_cookie("current_connection", "None") self.redirect("/connections_list")
def welcome(self, message): """ try to register the client and return the info message """ try: connection_id = message["connection_id"] r = Tdbmodel() # get the connection from the DB print(f"connecting to: {connection_id}") c = Connections() db_conf = c.find(c.where("_uuid") == connection_id) r.set_connection(db_conf=db_conf.to_dict()) try: result = r.db.tables() client_id = message["client_id"] if not client_id in self.dbclients: self.dbclients[client_id] = r info = {} info["tables"] = result info["hostname"] = db_conf.host info["dbname"] = db_conf.dbname data = {"method": "welcome", "type": "info", "data": info} except Exception as e: print(str(e)) data = { "method": "welcome", "type": "error", "message": "Could not connect to host...", "redirect": True, "redirect_url": "/connections_list", "data": "Nothing" } return json.dumps(data) except Exception as e: data = {"method": "welcome", "type": "error", "data": str(e)} return json.dumps(data)
def page(self, page=0): m=Model() res=m.page(page=int(page), page_size=myapp["page_size"]) self.success(message="connections page: #" +str(page), data=res )
def list(self): m=Model() res = m.get_all() self.success(message="connections, index", data=res)
def list_nice(self): m=Model() res = m.get_all() # remark: default template will be handler + method => connections_list_nice.tmpl self.success(message="connections, index", data=res, connected=False)
def show(self, id=None): m=Model() res=m.find_by_id(id) self.success(message="connections show", data=res)