def returnObjectOrResult(self, resultCode, objectToReturn=None, encoderForObject=None): self.response.headers["Content-Type"] = "application/json" if objectToReturn is None or (isinstance(objectToReturn, list) and len(objectToReturn) == 0): errorResult = Error.get_by_key_name(resultCode) return ErrorEncoder().encode(errorResult) else: return encoderForObject.encode(objectToReturn)
def get(self, errorId): theErrorToReturn = Error.get_by_key_name(errorId) self.response.headers["Content-Type"] = "application/json" if theErrorToReturn is None: theJsonResponse = {} else: theJsonResponse = theErrorToReturn.__dict__["_entity"] self.response.out.write(json.dumps(theJsonResponse))
def put(self, errorId): theJsonRequest = json.loads(self.request.body) theErrorDescription = theJsonRequest["description"] theErrorLongDescription = theJsonRequest["longDescription"] theErrorToUpdate = Error.get_by_key_name(errorId) theErrorToUpdate.description = theErrorDescription theErrorToUpdate.longDescription = theErrorLongDescription theErrorToUpdate.put() self.response.headers["Content-Type"] = "application/json" theJsonResponse = {"result": 0, "message": "Error modificado correctamente"} self.response.out.write(json.dumps(theJsonResponse))
def errorFromDBHook(self, dictionary): return Error.get_by_key_name(dictionary['errorCodeId'])