def edit_one(session, element, attrib, value): if attrib == "room": if value == "": element.room = None else: my_room = Room.get_one(session, value) if isinstance(my_room, Room): element.room = my_room else: return User.ERROR_VALUE_NOT_VALID elif attrib == "receive_room": if value == "": element.receive_room = None else: my_room = Room.get_one(session, value) if isinstance(my_room, Room): element.receive_room = my_room else: return User.ERROR_VALUE_NOT_VALID elif attrib == "admin": if value == "True": element.admin = True else: element.admin = False else: return Role.edit_one(element, attrib, value)
def PUT(self, name, attrib=None): session = cherrypy.request.db cherrypy.response.headers['content-type'] = 'text/plain' body = cherrypy.request.body.read().decode() if (cherrypy.request.process_request_body == True): if attrib == None: element = Room.import_one(session, body, name=name) if isinstance(element, Room): element = Room.add_one(session, element) if isinstance(element, Room): client_com.send_requests_process({"backend": None, "monitor": None, "user": None}, "PUT", "room", name, attrib, body, "text/xml") return "Room %s added" % name elif element == Room.ERROR_ELEMENT_ALREADY_EXISTS: raise cherrypy.HTTPError("403", "Room %s already exists" % name) elif element == Room.ERROR_TAG_NOT_VALID: raise cherrypy.HTTPError("400", "Tag not valid") else: element = Room.get_one(session, name) if isinstance(element, Room): element = Room.edit_one(session, element, attrib, body) if isinstance(element, Room): client_com.send_requests_process({"backend": None, "monitor": None, "user": None}, "PUT", "room", name, attrib, body, "text/plain") return "Room %s attribute %s value %s changed" % (name, attrib, body) elif element == Room.ERROR_ATTRIB_NOT_VALID: raise cherrypy.HTTPError("404", "Attribute % not found" % attrib) elif element == Room.ERROR_ELEMENT_NOT_EXISTS: raise cherrypy.HTTPError("404", "Room %s not found" % name) else: raise cherrypy.HTTPError("400", "No body specified")
def DELETE(self, name): session = cherrypy.request.db cherrypy.response.headers['content-type'] = 'text/plain' element = Room.get_one(session, name) if isinstance(element, Room): element = Room.del_one(session, element) if isinstance(element, Room): client_com.send_requests_process({"backend": None, "monitor": None, "user": None}, "DELETE", "room", name, None, None, None) return "Room %s deleted" % name elif element == Room.ERROR_ELEMENT_NOT_EXISTS: raise cherrypy.HTTPError("404", "User %s not found" % name)
def GET(self, name=None): session = cherrypy.request.db cherrypy.response.headers['content-type'] = 'text/xml' if name == None: elements = Room.get_all(session) if isinstance(elements, list): if isinstance(cherrypy.request.role, User): return Room.export_all(elements, ["name"]) else: return Room.export_all(elements, "all") else: element = Room.get_one(session, name) if isinstance(element, Room): return Room.export_one(element, "all") else: raise cherrypy.HTTPError("404", "Room %s not found" % name)
def POST(self, name): session = cherrypy.request.db cherrypy.response.headers['content-type'] = 'text/plain' body = cherrypy.request.body.read().decode() if (cherrypy.request.process_request_body == True): element = Room.get_one(session, name) if isinstance(element, Room): element = Room.import_one(session, body, element=element) if isinstance(element, Room): client_com.send_requests_process({"backend": None, "monitor": None, "user": None}, "POST", "room", name, None, body, "text/xml") return "Room %s updated" % name elif element == Room.ERROR_TAG_NOT_VALID: raise cherrypy.HTTPError("400", "Tag not valid") elif element == Room.ERROR_ELEMENT_NOT_EXISTS: raise cherrypy.HTTPError("404", "Room %s not found" % name) else: raise cherrypy.HTTPError("400", "No body specified")
def get_all(session, attrib=None, value=None, active=None): if active == None: filter_active = User.active != None else: filter_active = User.active == active if attrib == None: return session.query(User).filter(filter_active).all() elif attrib == "room": my_room = Room.get_one(session, value) if isinstance(my_room, Room): return session.query(User).filter(User.room == my_room, filter_active).all() else: return User.ERROR_VALUE_NOT_VALID elif attrib == "receiveroom": my_room = Room.get_one(session, value) if isinstance(my_room, Room): return session.query(User).filter(User.receive_room == my_room, filter_active).all() else: return User.ERROR_VALUE_NOT_VALID else: return User.ERROR_ATTRIB_NOT_VALID
def edit_one(session, element, attrib, value): if attrib == "room": if value == "": element.room = None else: my_room = Room.get_one(session, value) if isinstance(my_room, Room): element.room = my_room else: return Node.ERROR_VALUE_NOT_VALID elif attrib == "title": element.title = value elif attrib == "tyoe": element.type = value elif attrib == "input": element.input = value elif attrib == "output": element.output = value else: return Role.edit_one(element, attrib, value)