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 = User.get_one(session, name) if isinstance(element, User): element = User.import_one(session, body, element=element) if isinstance(element, User): client_com.send_requests_process( {"backend": None, "monitor": None}, "POST", "user", name, None, body, "text/xml" ) return "User %s updated" % name elif element == User.ERROR_VALUE_NOT_VALID: raise cherrypy.HTTPError("403", "Value of attribute not valid") elif element == User.ERROR_TAG_NOT_VALID: raise cherrypy.HTTPError("400", "Tag not valid") elif element == User.ERROR_ELEMENT_NOT_EXISTS: raise cherrypy.HTTPError("404", "User %s not found" % name) else: raise cherrypy.HTTPError("400", "No body specified")
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 = User.import_one(session, body, name=name) if isinstance(element, User): element = User.add_one(session, element) if isinstance(element, User): client_com.send_requests_process( {"backend": None, "monitor": None}, "PUT", "user", name, attrib, body, "text/xml" ) return "User %s added" % name elif element == User.ERROR_ELEMENT_ALREADY_EXISTS: raise cherrypy.HTTPError("403", "User %s alread exists" % name) elif element == User.ERROR_VALUE_NOT_VALID: raise cherrypy.HTTPError("403", "Value of attribute not valid") elif element == User.ERROR_TAG_NOT_VALID: raise cherrypy.HTTPError("400", "Tag not valid") else: element = User.get_one(session, name) if isinstance(element, User): element = User.edit_one(session, element, attrib, body) if isinstance(element, User): client_com.send_requests_process( {"backend": None, "monitor": None}, "PUT", "user", name, attrib, body, "text/plain" ) return "User %s attribute %s value %s changed" % (name, attrib, body) elif element == User.ERROR_VALUE_NOT_VALID: raise cherrypy.HTTPError("403", "Value %s of attribute %s not valid" % (body, attrib)) elif element == User.ERROR_ATTRIB_NOT_VALID: raise cherrypy.HTTPError("404", "Attribute %s not found" % attrib) elif element == User.ERROR_ELEMENT_NOT_EXISTS: raise cherrypy.HTTPError("404", "User %s not found" % name) else: raise cherrypy.HTTPError("400", "No body specified")