def post(self): request_data = json.loads(self.request.body) logging.info(request_data) player = current_user_player() equipment_to_buy = get_equipment_from_name(request_data['equipment_name']) # VALIDATION if OwnedEquipment.query(OwnedEquipment.player == player.key, OwnedEquipment.name == equipment_to_buy['name']).count() > 0: error_400(self.response, "ERROR_HAVE_EQUIPMENT", "You already have the item '%s'." % equipment_to_buy['name']) return if equipment_to_buy['cost'] > player.cash: error_400(self.response, "ERROR_NOT_ENOUGH_CASH", "Cant afford item. You have %s, the cost is %s" % (player.cash, equipment_to_buy['cost'])) return # BUY new_equipment = OwnedEquipment( player=player.key, name=equipment_to_buy['name'], type=equipment_to_buy['type'] ).put().get() player.cash -= equipment_to_buy['cost'] player.put() set_json_response(self.response, new_equipment.get_data())