def _write_all_objects_of_type(self, model_type): '''This finds all objects of a given type and writes them as a response''' allItems = self._perform_filter(getattr(model, model_type)) #Write JSON back to the client self.response.headers['Content-Type'] = "application/json" self.response.write(parser.get_json_string(allItems))
def _write_all(self): '''Writes every single entity stored in the DB''' isLoadKeysOnly = self.request.get('load') != 'all' allEntities = [] for k in metadata.get_kinds(): logging.getLogger().info("TYPE:" + k) if not k.startswith('_'): allEntities.extend(getattr(model, k).query().fetch(keys_only=isLoadKeysOnly)) self.response.headers['Content-Type'] = "application/json" self.response.write(parser.get_json_string(allEntities))
def _write_all(self): '''Writes every single entity stored in the DB''' isLoadKeysOnly = self.request.get('load') != 'all' allEntities = [] for k in metadata.get_kinds(): logging.getLogger().info("TYPE:" + k) if not k.startswith('_'): allEntities.extend( getattr(model, k).query().fetch(keys_only=isLoadKeysOnly)) self.response.headers['Content-Type'] = "application/json" self.response.write(parser.get_json_string(allEntities))
def _write_object_with_id(self, model_type, model_id): ''' Writes an entity back to the client based on id. The value written will always be in JSON format. All filters will be ignored. It will by default perform a load of all properties. Why else would you call this? ''' #Simply get the object using NDB's class methods obj_result = [getattr(model, model_type).get_by_id(model_id)] #We need to make these objects return arrays too objectString = parser.get_json_string(obj_result) #Return the values in the entity dictionary self.response.headers['Content-Type'] = "application/json" self.response.write(objectString)
def _write_object_with_encodedkey(self, encoded_key, property_name=None): ''' Writes an entity back to the client based on id. The value written will always be in JSON format. All filters will be ignored. It will by default perform a load of all properties. Why else would you call this? ''' #Simply get the object using NDB's class methods try: key = ndb.Key(urlsafe=encoded_key) obj_result = key.get() #We need to make these objects return arrays too objectString = parser.get_json_string(obj_result, property_name) #Return the values in the entity dictionary self.response.headers['Content-Type'] = "application/json" self.response.write(objectString) except Exception, e: self.render_error(int(400), 'key_error', "The Key supplied in the URI was not valid - " + str(e)) return
def _write_all_objects_of_type(self, model_type, list_props): '''This finds all objects of a given type and writes them as a response''' model_handler = getattr(model, model_type) model_query = parser.ModelQuery() model_query.parse(self, model_handler) if model_query.error: self.render_error(model_query.error_code, model_query.error, model_query.error_description) else: model_query.query_expr = self.authorizer.check_query( self, model_query.query_expr, model_query.query_params) models = model_query.perform_filter(self, model_handler, model_query) if model_query.fetch_cursor: list_props[parser.QUERY_CURSOR_PARAM] = model_query.fetch_cursor models.append(list_props) models = self.authorizer.filter_read(self, models) #Write JSON back to the client self.response.headers['Content-Type'] = "application/json" self.response.write(parser.get_json_string(models))