From 4089777f8882a2b47d59ca456542222b22836f39 Mon Sep 17 00:00:00 2001 From: Burathar Date: Wed, 29 Jul 2020 11:10:53 +0200 Subject: [PATCH] Implement hide/publish/pause/resume game, fix database boolean default --- app/main/routes.py | 10 +++++----- app/models/game.py | 8 ++++---- app/models/game_state.py | 2 +- app/models/notification_player.py | 2 +- app/templates/edit_game.html | 3 +-- documentation/gamestate.txt | 2 +- ...50a_replace_gamestate_with_hidden_and_paused.py} | 13 +++++++------ 7 files changed, 20 insertions(+), 20 deletions(-) rename migrations/versions/{d87b14d6a90c_add_pcp_review.py => 7a3183ce450a_replace_gamestate_with_hidden_and_paused.py} (93%) diff --git a/app/main/routes.py b/app/main/routes.py index d90a1b4..5a4872c 100644 --- a/app/main/routes.py +++ b/app/main/routes.py @@ -104,7 +104,7 @@ def publish_game(game_name): game.hidden = False db.session.commit() flash(f"Game '{game.name}' has been published!") - return redirect(url_for('main.index')) + return redirect(url_for('main.game_dashboard', game_name=game.name)) @bp.route('/game//hide') @login_required @@ -113,7 +113,7 @@ def hide_game(game_name): game.hidden = True db.session.commit() flash(f"Game '{game.name}' has been hidden!") - return redirect(url_for('main.index')) + return redirect(url_for('main.game_dashboard', game_name=game.name)) @bp.route('/game//pause') @login_required @@ -122,7 +122,7 @@ def pause_game(game_name): game.paused = True db.session.commit() flash(f"Game '{game.name}' has been paused!") - return redirect(url_for('main.index')) + return redirect(url_for('main.game_dashboard', game_name=game.name)) @bp.route('/game//unpause') @bp.route('/game//resume') @@ -131,8 +131,8 @@ def resume_game(game_name): game = get_game_if_owner(game_name) game.paused = False db.session.commit() - flash(f"Game '{game.name}' has been paused!") - return redirect(url_for('main.index')) + flash(f"Game '{game.name}' has been resumed!") + return redirect(url_for('main.game_dashboard', game_name=game.name)) @bp.route('/game//dashboard') diff --git a/app/models/game.py b/app/models/game.py index 651d760..df1ffb8 100644 --- a/app/models/game.py +++ b/app/models/game.py @@ -11,8 +11,8 @@ class Game(db.Model): id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(64), index=True, unique=True, nullable=False) #state = db.Column(db.Enum(GameState), server_default=GameState(1).name, nullable=False) - hidden = db.Column(db.Boolean, server_default='True', nullable=False) - paused = db.Column(db.Boolean, server_default='False', nullable=False) + hidden = db.Column(db.Boolean, server_default='1', nullable=False) + paused = db.Column(db.Boolean, server_default='0', nullable=False) start_time = db.Column(db.DateTime) end_time = db.Column(db.DateTime) players = db.relationship( @@ -71,7 +71,7 @@ class Game(db.Model): for pcp in pcps if pcp.review == Review.none] def is_active(self): - return self.get_state == GameState.active + return self.get_state() == GameState.active def get_state(self): now = datetime.utcnow() @@ -85,7 +85,7 @@ class Game(db.Model): end = (self.end_time or datetime.max).replace(tzinfo=None) if start < now < end: # During Game if self.paused: - return GameState.interrupted + return GameState.paused return GameState.active if now > end: # After Game diff --git a/app/models/game_state.py b/app/models/game_state.py index 8b5b22f..a02280a 100644 --- a/app/models/game_state.py +++ b/app/models/game_state.py @@ -4,6 +4,6 @@ class GameState(Enum): hidden = 1 published = 2 active = 3 - interrupted = 4 + paused = 4 finished = 5 \ No newline at end of file diff --git a/app/models/notification_player.py b/app/models/notification_player.py index 4ec8327..2978ef5 100644 --- a/app/models/notification_player.py +++ b/app/models/notification_player.py @@ -4,7 +4,7 @@ class NotificationPlayer(db.Model): __tablename__ = 'notification_player' notification_id = db.Column(db.Integer, db.ForeignKey('notification.id'), primary_key=True, nullable=False) game_player_id = db.Column(db.Integer, db.ForeignKey('game_player.id'), primary_key=True, nullable=False) - been_shown = db.Column(db.Boolean, server_default='True', nullable=False) + been_shown = db.Column(db.Boolean, server_default='0', nullable=False) notification = db.relationship('Notification', back_populates='notification_recipients') recipient = db.relationship('GamePlayer', back_populates='player_notifications') \ No newline at end of file diff --git a/app/templates/edit_game.html b/app/templates/edit_game.html index 67185b4..2f0fb72 100644 --- a/app/templates/edit_game.html +++ b/app/templates/edit_game.html @@ -10,7 +10,7 @@ {% block app_content %}

{{ title }}

-
+

{{ form.hidden_tag() }} @@ -48,7 +48,6 @@ {% endif %} - {% if game.paused %} diff --git a/documentation/gamestate.txt b/documentation/gamestate.txt index a8e1a9b..7fd96e1 100644 --- a/documentation/gamestate.txt +++ b/documentation/gamestate.txt @@ -4,5 +4,5 @@ This is an attribute of the Game class. It will be implemented as an enum contai hidden = 1 published = 2 active = 3 -interrupted = 4 +paused = 4 finished = 5 diff --git a/migrations/versions/d87b14d6a90c_add_pcp_review.py b/migrations/versions/7a3183ce450a_replace_gamestate_with_hidden_and_paused.py similarity index 93% rename from migrations/versions/d87b14d6a90c_add_pcp_review.py rename to migrations/versions/7a3183ce450a_replace_gamestate_with_hidden_and_paused.py index 03985d1..5db2d22 100644 --- a/migrations/versions/d87b14d6a90c_add_pcp_review.py +++ b/migrations/versions/7a3183ce450a_replace_gamestate_with_hidden_and_paused.py @@ -1,8 +1,8 @@ -"""add pcp review +"""replace gamestate with hidden and paused -Revision ID: d87b14d6a90c +Revision ID: 7a3183ce450a Revises: -Create Date: 2020-07-21 21:47:51.061829 +Create Date: 2020-07-29 10:55:07.589462 """ from alembic import op @@ -10,7 +10,7 @@ import sqlalchemy as sa # revision identifiers, used by Alembic. -revision = 'd87b14d6a90c' +revision = '7a3183ce450a' down_revision = None branch_labels = None depends_on = None @@ -21,7 +21,8 @@ def upgrade(): op.create_table('game', sa.Column('id', sa.Integer(), nullable=False), sa.Column('name', sa.String(length=64), nullable=False), - sa.Column('state', sa.Enum('hidden', 'published', 'active', 'interrupted', 'finished', name='gamestate'), server_default='hidden', nullable=False), + sa.Column('hidden', sa.Boolean(), server_default='1', nullable=False), + sa.Column('paused', sa.Boolean(), server_default='0', nullable=False), sa.Column('start_time', sa.DateTime(), nullable=True), sa.Column('end_time', sa.DateTime(), nullable=True), sa.PrimaryKeyConstraint('id') @@ -79,7 +80,7 @@ def upgrade(): op.create_table('notification_player', sa.Column('notification_id', sa.Integer(), nullable=False), sa.Column('game_player_id', sa.Integer(), nullable=False), - sa.Column('been_shown', sa.Boolean(), server_default='True', nullable=False), + sa.Column('been_shown', sa.Boolean(), server_default='0', nullable=False), sa.ForeignKeyConstraint(['game_player_id'], ['game_player.id'], ), sa.ForeignKeyConstraint(['notification_id'], ['notification.id'], ), sa.PrimaryKeyConstraint('notification_id', 'game_player_id')