diff --git a/app/models/game_player.py b/app/models/game_player.py
index fd0e99b..1765c62 100644
--- a/app/models/game_player.py
+++ b/app/models/game_player.py
@@ -36,8 +36,8 @@ class GamePlayer(db.Model):
def last_location(self):
# pylint: disable=no-member
- self.user.last_location(self.game)
+ return self.user.last_location(self.game)
def locations_during_game(self):
# pylint: disable=no-member
- self.user.locations_during_game(self.game)
+ return self.user.locations_during_game(self.game)
diff --git a/app/models/user.py b/app/models/user.py
index 26836cf..0032b41 100644
--- a/app/models/user.py
+++ b/app/models/user.py
@@ -28,7 +28,7 @@ class User(UserMixin, db.Model):
locations = db.relationship(
'Location',
lazy='select',
- backref=db.backref('player', lazy='joined'),
+ backref=db.backref('user', lazy='joined'),
cascade="save-update, merge, delete, delete-orphan")
def set_password(self, password):
@@ -50,7 +50,7 @@ class User(UserMixin, db.Model):
return self.locations
game_start = game.start_time or datetime.min
game_end = game.end_time or datetime.max
- return (location for location in self.locations if location.timestamp > game_start and location.timestamp < game_end)
+ return [location for location in self.locations if location.timestamp > game_start and location.timestamp < game_end]
def last_location(self, game=None):
# pylint: disable=not-an-iterable
diff --git a/app/templates/game_hunter_dashboard.html b/app/templates/game_hunter_dashboard.html
index 7e19ae4..7308053 100644
--- a/app/templates/game_hunter_dashboard.html
+++ b/app/templates/game_hunter_dashboard.html
@@ -28,7 +28,7 @@
{{ bunny.user.name }} |
{{ bunny.player_caught_by_players | selectattr('catching_player', '==', current_user.player_in(game)) |list|length}} |
- {% with location = bunny.user.last_location(game) %}
+ | {% with location = bunny.last_location() %}
{% if location %}{{ moment(location.timestamp).fromNow()}}: {% endif %}
{{ location }}
{% endwith %} |
diff --git a/migrations/versions/fa85e732aa96_reset_migrations.py b/migrations/versions/fa85e732aa96_reset_migrations.py
new file mode 100644
index 0000000..3558f57
--- /dev/null
+++ b/migrations/versions/fa85e732aa96_reset_migrations.py
@@ -0,0 +1,119 @@
+"""reset migrations
+
+Revision ID: fa85e732aa96
+Revises:
+Create Date: 2020-07-19 22:51:26.430851
+
+"""
+from alembic import op
+import sqlalchemy as sa
+
+
+# revision identifiers, used by Alembic.
+revision = 'fa85e732aa96'
+down_revision = None
+branch_labels = None
+depends_on = None
+
+
+def upgrade():
+ # ### commands auto generated by Alembic - please adjust! ###
+ 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('initiated', 'published', 'started', 'interrupted', 'finished', name='gamestate'), server_default='initiated', nullable=False),
+ sa.Column('start_time', sa.DateTime(), nullable=True),
+ sa.Column('end_time', sa.DateTime(), nullable=True),
+ sa.PrimaryKeyConstraint('id')
+ )
+ op.create_index(op.f('ix_game_name'), 'game', ['name'], unique=True)
+ op.create_table('user',
+ sa.Column('id', sa.Integer(), nullable=False),
+ sa.Column('name', sa.String(length=64), nullable=False),
+ sa.Column('auth_hash', sa.String(length=32), nullable=True),
+ sa.Column('password_hash', sa.String(length=128), nullable=True),
+ sa.Column('last_login', sa.DateTime(), nullable=True),
+ sa.PrimaryKeyConstraint('id'),
+ sa.UniqueConstraint('auth_hash'),
+ sa.UniqueConstraint('name')
+ )
+ op.create_table('game_player',
+ sa.Column('id', sa.Integer(), nullable=False),
+ sa.Column('game_id', sa.Integer(), nullable=False),
+ sa.Column('user_id', sa.Integer(), nullable=False),
+ sa.Column('role', sa.Enum('none', 'owner', 'hunter', 'bunny', name='role'), server_default='none', nullable=False),
+ sa.ForeignKeyConstraint(['game_id'], ['game.id'], ),
+ sa.ForeignKeyConstraint(['user_id'], ['user.id'], ),
+ sa.PrimaryKeyConstraint('id'),
+ sa.UniqueConstraint('game_id', 'user_id', name='_game_user_uc')
+ )
+ op.create_table('location',
+ sa.Column('id', sa.Integer(), nullable=False),
+ sa.Column('user_id', sa.Integer(), nullable=False),
+ sa.Column('longitude', sa.Numeric(precision=15, scale=10, asdecimal=False), nullable=False),
+ sa.Column('latitude', sa.Numeric(precision=15, scale=10, asdecimal=False), nullable=False),
+ sa.Column('timestamp', sa.DateTime(), server_default=sa.text('(CURRENT_TIMESTAMP)'), nullable=False),
+ sa.ForeignKeyConstraint(['user_id'], ['user.id'], ),
+ sa.PrimaryKeyConstraint('id')
+ )
+ op.create_table('notification',
+ sa.Column('id', sa.Integer(), nullable=False),
+ sa.Column('game_id', sa.Integer(), nullable=False),
+ sa.Column('message', sa.Text(), nullable=False),
+ sa.Column('type', sa.String(length=64), nullable=False),
+ sa.Column('timestamp', sa.DateTime(), server_default=sa.text('(CURRENT_TIMESTAMP)'), nullable=False),
+ sa.ForeignKeyConstraint(['game_id'], ['game.id'], ),
+ sa.PrimaryKeyConstraint('id')
+ )
+ op.create_table('objective',
+ sa.Column('id', sa.Integer(), nullable=False),
+ sa.Column('name', sa.String(length=64), nullable=True),
+ sa.Column('game_id', sa.Integer(), nullable=False),
+ sa.Column('hash', sa.String(length=32), nullable=False),
+ sa.Column('longitude', sa.Numeric(precision=15, scale=10, asdecimal=False), nullable=True),
+ sa.Column('latitude', sa.Numeric(precision=15, scale=10, asdecimal=False), nullable=True),
+ sa.ForeignKeyConstraint(['game_id'], ['game.id'], ),
+ sa.PrimaryKeyConstraint('id'),
+ sa.UniqueConstraint('hash')
+ )
+ 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.ForeignKeyConstraint(['game_player_id'], ['game_player.id'], ),
+ sa.ForeignKeyConstraint(['notification_id'], ['notification.id'], ),
+ sa.PrimaryKeyConstraint('notification_id', 'game_player_id')
+ )
+ op.create_table('player_caught_player',
+ sa.Column('id', sa.Integer(), server_default='-1', autoincrement=True, nullable=False),
+ sa.Column('catching_player_id', sa.Integer(), nullable=False),
+ sa.Column('caught_player_id', sa.Integer(), nullable=False),
+ sa.Column('timestamp', sa.DateTime(), server_default=sa.text('(CURRENT_TIMESTAMP)'), nullable=False),
+ sa.ForeignKeyConstraint(['catching_player_id'], ['game_player.id'], ),
+ sa.ForeignKeyConstraint(['caught_player_id'], ['game_player.id'], ),
+ sa.PrimaryKeyConstraint('id')
+ )
+ op.create_table('player_found_objective',
+ sa.Column('objective_id', sa.Integer(), server_default='-1', nullable=False),
+ sa.Column('game_player_id', sa.Integer(), server_default='-1', nullable=False),
+ sa.Column('timestamp', sa.DateTime(), server_default=sa.text('(CURRENT_TIMESTAMP)'), nullable=False),
+ sa.ForeignKeyConstraint(['game_player_id'], ['game_player.id'], ),
+ sa.ForeignKeyConstraint(['objective_id'], ['objective.id'], ),
+ sa.PrimaryKeyConstraint('objective_id', 'game_player_id')
+ )
+ # ### end Alembic commands ###
+
+
+def downgrade():
+ # ### commands auto generated by Alembic - please adjust! ###
+ op.drop_table('player_found_objective')
+ op.drop_table('player_caught_player')
+ op.drop_table('notification_player')
+ op.drop_table('objective')
+ op.drop_table('notification')
+ op.drop_table('location')
+ op.drop_table('game_player')
+ op.drop_table('user')
+ op.drop_index(op.f('ix_game_name'), table_name='game')
+ op.drop_table('game')
+ # ### end Alembic commands ###