Browse Source

fix game dashboard

feature_tests
Burathar 5 years ago
parent
commit
9bf9156e99
  1. 14
      app/routes.py
  2. 8
      app/templates/game_dashboard.html
  3. 6
      app/templates/index.html

14
app/routes.py

@ -1,7 +1,8 @@
from flask import render_template, flash, redirect, url_for, request from flask import render_template, flash, redirect, url_for, request
from flask_login import login_user, logout_user, current_user, login_required from flask_login import login_user, logout_user, current_user, login_required
from sqlalchemy import and_
from app import app, db 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 from app.forms import LoginForm, RegistrationForm, CreateGameForm
@app.route('/', methods=['GET']) @app.route('/', methods=['GET'])
@ -49,7 +50,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.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.add(game)
db.session.commit() db.session.commit()
flash(f"'{game.name}' had been created!") flash(f"'{game.name}' had been created!")
@ -59,5 +60,10 @@ def create_game():
@login_required @login_required
@app.route('/game/<game_name>/dashboard') @app.route('/game/<game_name>/dashboard')
def game_dashboard(game_name): 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() 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) 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')

8
app/templates/game_dashboard.html

@ -1,7 +1,7 @@
{% extends 'base.html' %} {% extends 'base.html' %}
{% block app_content %} {% block app_content %}
<h1>{{ game.name }}Dashboard</h1> <h1>{{ game.name }} Dashboard</h1>
<h2>Players:</h2> <h2>Players:</h2>
<div class="table-responsive"> <div class="table-responsive">
@ -18,8 +18,10 @@
<tbody> <tbody>
{% for player in game.players %} {% for player in game.players %}
<tr> <tr>
<td><a href="{{ url_for(f'player/{player.name}') }}">{{ player.name }}</a></td> <td><a href="{{ url_for('game_player', game_name = game.name, player_name = player.name) }}">{{ player.name }}</a></td>
<td>{{ [gameplayer for gameplayer in p.player_games if gameplayer.game == g2][0].role }}</td> {% for gameplayer in player.player_games if gameplayer.game == game %}
<td>{{ gameplayer.role.name }}</td>
{% endfor %}
<td>{{ "Placeholder" }}</td> <td>{{ "Placeholder" }}</td>
<td>{{ "Placeholder" }}</td> <td>{{ "Placeholder" }}</td>
<td> Placeholder <td> <td> Placeholder <td>

6
app/templates/index.html

@ -20,12 +20,12 @@
{% for game in current_user.games %} {% for game in current_user.games %}
<tr> <tr>
<td>{{ game.name }}</td> <td>{{ game.name }}</td>
<td>{{ game.state }}</td> <td>{{ game.state.name}}</td>
<td>{{ game.start_time }}</td> <td>{{ game.start_time }}</td>
<td>{{ game.end_time }}</td> <td>{{ game.end_time }}</td>
<td> <td>
{% for gameplayer in current_user.player_games %} {% for gameplayer in current_user.player_games if gameplayer.game == game %}
{% if gameplayer.game == game %}{{ gameplayer.role }}{% endif %} {{ gameplayer.role.name }}
{% endfor %} {% endfor %}
</td> </td>
</tr> </tr>

Loading…
Cancel
Save