|
|
|
@ -1,7 +1,8 @@
@@ -1,7 +1,8 @@
|
|
|
|
|
from flask import render_template, flash, redirect, url_for, request |
|
|
|
|
from flask_login import login_user, logout_user, current_user, login_required |
|
|
|
|
from sqlalchemy import and_ |
|
|
|
|
from app import app, db |
|
|
|
|
from app.models import Player, Game, Role |
|
|
|
|
from app.models import Player, Game, Role, GamePlayer |
|
|
|
|
from app.forms import LoginForm, RegistrationForm, CreateGameForm |
|
|
|
|
|
|
|
|
|
@app.route('/', methods=['GET']) |
|
|
|
@ -49,7 +50,7 @@ def create_game():
@@ -49,7 +50,7 @@ def create_game():
|
|
|
|
|
form = CreateGameForm() |
|
|
|
|
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.gameplayers.append(GamePlayer(player=current_user, role=Role['owner'])) #check if this works, otherwise use 'owner' |
|
|
|
|
game.game_players.append(GamePlayer(player=current_user, role=Role['owner'])) #check if this works, otherwise use 'owner' |
|
|
|
|
db.session.add(game) |
|
|
|
|
db.session.commit() |
|
|
|
|
flash(f"'{game.name}' had been created!") |
|
|
|
@ -59,5 +60,10 @@ def create_game():
@@ -59,5 +60,10 @@ def create_game():
|
|
|
|
|
@login_required |
|
|
|
|
@app.route('/game/<game_name>/dashboard') |
|
|
|
|
def game_dashboard(game_name): |
|
|
|
|
game = Game.query.filter(Game.game_players.any(and_(GamePlayer.player.has(current_user), GamePlayer.role == 'owner'))).first_or_404() |
|
|
|
|
return render_template('game_dashboard.html', title = 'Game Dashboard', game=game) |
|
|
|
|
game = Game.query.filter(Game.game_players.any(and_(GamePlayer.player.has(Player.name == current_user.name), GamePlayer.role == 'owner'))).first_or_404() |
|
|
|
|
return render_template('game_dashboard.html', title = 'Game Dashboard', game=game) |
|
|
|
|
|
|
|
|
|
@login_required |
|
|
|
|
@app.route('/game/<game_name>/player/<player_name>') |
|
|
|
|
def game_player(game_name, player_name): |
|
|
|
|
return render_template("index.html", title='Home') |