def post(self): predator = self.request.get('predator') prey = self.request.get('prey') animal = Animal.get_by_id(int(predator), parent=PARENT) animal.prey.append(ndb.Key("FoodChain", 1, Animal, int(prey))) animal.put() self.redirect('/')
def get(self, animal_id): """ASWP-API Animal GET Args: animal_id (int): Animal ID Returns: type[Response]: Flask JSON Response with Animal data tuple: Tuple with error message and status code """ animal = Animal.get_by_id(animal_id) if animal: animal = Animal.to_dict(animal) if animal["price"] == None: animal["price"] = Specie.get_price(animal["specie"]) return jsonify(animal) else: return {"error": "Animal not found"}, 404
def prey_count_reduce(key, values): animal = Animal.get_by_id(int(key), parent=PARENT) yield "%s: %d\n" % (str(animal.name), len(values))