| 
						
						
							
								
							
						
						
					 | 
					 | 
					@ -8,8 +8,8 @@ from sqlalchemy import and_ | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					from app import db | 
					 | 
					 | 
					 | 
					from app import db | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					from app.main import bp | 
					 | 
					 | 
					 | 
					from app.main import bp | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					from app.models import User, Game, Role, GamePlayer, Objective, ObjectiveMinimalEncoder, LocationEncoder | 
					 | 
					 | 
					 | 
					from app.models import User, Game, Role, GamePlayer, Objective, ObjectiveMinimalEncoder, LocationEncoder, PlayerCaughtPlayer | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					from app.main.forms import CreateGameForm, ObjectiveForm, PlayerAddForm, UserCreateForm, PlayerUpdateForm | 
					 | 
					 | 
					 | 
					from app.main.forms import CreateGameForm, ObjectiveForm, PlayerAddForm, UserCreateForm, PlayerUpdateForm, CatchBunnyForm | 
				
			
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					@bp.before_app_request | 
					 | 
					 | 
					 | 
					@bp.before_app_request | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					def before_request(): | 
					 | 
					 | 
					 | 
					def before_request(): | 
				
			
			
		
	
	
		
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
					 | 
					@ -32,7 +32,7 @@ def create_game(): | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    form = CreateGameForm() | 
					 | 
					 | 
					 | 
					    form = CreateGameForm() | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    if form.validate_on_submit(): | 
					 | 
					 | 
					 | 
					    if form.validate_on_submit(): | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        game = Game(name=form.game_name.data, start_time=form.start_time.data, end_time=form.end_time.data) | 
					 | 
					 | 
					 | 
					        game = Game(name=form.game_name.data, start_time=form.start_time.data, end_time=form.end_time.data) | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        game.game_players.append(GamePlayer(user=current_user, role=Role['owner'])) | 
					 | 
					 | 
					 | 
					        game.players.append(GamePlayer(user=current_user, role=Role['owner'])) | 
				
			
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        db.session.add(game) | 
					 | 
					 | 
					 | 
					        db.session.add(game) | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        db.session.commit() | 
					 | 
					 | 
					 | 
					        db.session.commit() | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        flash(f"'{game.name}' had been created!") | 
					 | 
					 | 
					 | 
					        flash(f"'{game.name}' had been created!") | 
				
			
			
		
	
	
		
		
			
				
					| 
						
							
								
							
						
						
							
								
							
						
						
					 | 
					 | 
					@ -73,6 +73,36 @@ def game_dashboard(game_name): | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    if role is None: | 
					 | 
					 | 
					 | 
					    if role is None: | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        abort(403) | 
					 | 
					 | 
					 | 
					        abort(403) | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					@bp.route('/game/<game_name>/catch_bunny', methods=['GET', 'POST']) | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					@login_required | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					def catch_bunny(game_name): | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					    game = Game.query.filter_by(name=game_name).first_or_404() | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					    if current_user.role_in_game(game) is not Role.hunter: | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        flash('Only hunters can catch bunnies!') | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        abort(403) | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					     | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					    game_bunnies = [gameplayer for gameplayer in game.game_players if gameplayer.role == Role.bunny] | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					     | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					    form = CatchBunnyForm() | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					    form.bunny.choices = [(player.user.id, player.user.name) for player in game_bunnies] | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					    parsed_bunny_name = request.args.get('bunny_name', default='', type=str) | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					    if parsed_bunny_name: | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        bunny = [gameplayer for gameplayer in game_bunnies if gameplayer.user.name == parsed_bunny_name] | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        if bunny: | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					            # pylint: disable=no-member | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					            form.bunny.default = bunny[0].user.id | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					            form.process() | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					    if form.validate_on_submit(): | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        bunny = [gameplayer for gameplayer in game_bunnies if gameplayer.user.id == form.bunny.data] | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        pcp = PlayerCaughtPlayer(catching_player=current_user.player_in(game), caught_player=bunny[0], photo_reference='To be Impemented') | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        db.session.add(pcp) | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        db.session.commit() | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        flash(f"You caught '{bunny[0].user.name}'! The submitted photo will be reviewd by a game owner.") | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        return redirect(url_for('main.game_dashboard', game_name=game.name)) | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					    return render_template('catch_bunny.html', title='Catch Bunny', form=form, game=game) | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					@bp.route('/game/<game_name>/adduser', methods=['GET', 'POST']) | 
					 | 
					 | 
					 | 
					@bp.route('/game/<game_name>/adduser', methods=['GET', 'POST']) | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					@bp.route('/game/<game_name>/addplayer', methods=['GET', 'POST']) | 
					 | 
					 | 
					 | 
					@bp.route('/game/<game_name>/addplayer', methods=['GET', 'POST']) | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					@login_required | 
					 | 
					 | 
					 | 
					@login_required | 
				
			
			
		
	
	
		
		
			
				
					| 
						
							
								
							
						
						
						
					 | 
					 | 
					
  |