~muirrum/comortas

64fb2df193db515f4fc503495785e38aaa97bf33 — Cara Salter 3 years ago 97ff0b1
Add profile sections
M fllscoring/__init__.py => fllscoring/__init__.py +6 -0
@@ 40,5 40,11 @@ def create_app():
    import fllscoring.profile
    app.register_blueprint(profile.bp)

    import fllscoring.setup
    app.register_blueprint(setup.bp)

    import fllscoring.scoring
    app.register_blueprint(scoring.bp)


    return app
\ No newline at end of file

M fllscoring/models.py => fllscoring/models.py +2 -0
@@ 1,3 1,5 @@
from sqlalchemy import ForeignKey

from fllscoring import db

from flask_login import UserMixin

A fllscoring/scoring/__init__.py => fllscoring/scoring/__init__.py +14 -0
@@ 0,0 1,14 @@
from flask import Blueprint

from flask_login import login_required

bp = Blueprint("scoring", __name__, url_prefix="/scoring")

@bp.route('/home')
@login_required
def home():
    return "TODO"

@bp.route("/leaderboard_home")
def leaderboard_home():
    return "TODO"
\ No newline at end of file

A fllscoring/setup/__init__.py => fllscoring/setup/__init__.py +57 -0
@@ 0,0 1,57 @@
from flask import Blueprint, render_template, redirect, url_for, flash, abort

from flask_login import login_required, current_user

from fllscoring.models import Tournaments, Team
from fllscoring.setup.forms import NewTournamentForm, NewTeamForm
from fllscoring import db

bp = Blueprint('setup', __name__, url_prefix="/setup")

@bp.route("/home")
@login_required
def home():
    tournaments = Tournaments.query.filter_by(owner_id=current_user.user_id).all()
    return render_template('setup/home.html', title="Tournament Setup", tournaments=tournaments)

@bp.route("/create_tournament", methods=["GET", "POST"])
def new_tournament():
    form = NewTournamentForm()

    if form.validate_on_submit():
        print(current_user)
        u = current_user._get_current_object()
        tourney = Tournaments(owner_id=u.user_id, tournament_name=form.tournament_name.data)
        print(f"Created tourney {tourney}")
        db.session.add(tourney)
        print(f"Added tourney to session")
        db.session.commit()
        print("Committed")
        return redirect(url_for("setup.home"))
    else:
        for e in form.errors:
            flash(e)

    return render_template("setup/create_tournament.html", form=form, title="New Tournament")

@bp.route("/manage_tournament/<int:id>", methods=["GET", "POST"])
@login_required
def manage_tournament(id):
    tournament = Tournaments.query.filter_by(id=id).first()
    teams = Team.query.filter_by(tournament=id).all()
    if tournament is None:
        abort(404)
    return render_template("setup/tournament_mgmt.html", title=f"Update tournament {tournament.tournament_name}", tournament=tournament, teams=teams)

@bp.route("/new_team/<int:tournament_id>", methods=["GET", "POST"])
@login_required
def new_team(tournament_id):
    form = NewTeamForm()

    if form.validate_on_submit():
        team = Team(tournament=tournament_id, team_number=form.team_number.data,team_name=form.team_name.data, team_town=form.team_town.data)

        db.session.add(team)
        db.session.commit()
        return redirect(url_for("setup.manage_tournament", id=tournament_id))
    return render_template("setup/new_team.html", form=form, title=f"New Team for tournament {tournament_id}")
\ No newline at end of file

A fllscoring/setup/forms.py => fllscoring/setup/forms.py +12 -0
@@ 0,0 1,12 @@
from flask_wtf import FlaskForm
from wtforms.fields import StringField, IntegerField
from wtforms.validators import DataRequired


class NewTournamentForm(FlaskForm):
    tournament_name = StringField(label="Name", validators=[DataRequired()])

class NewTeamForm(FlaskForm):
    team_number = IntegerField(label="Team Number", validators=[DataRequired()])
    team_name = StringField(label="Team Nickname")
    team_town = StringField(label="Team Town")

M fllscoring/templates/profile/profile.html => fllscoring/templates/profile/profile.html +16 -0
@@ 4,4 4,20 @@
<h1>Welcome, {{ current_user.username }}</h1>
<p>Here you can access our services. If this is a local installation, please see the documentation for how to register yourself as a super-admin.</p>

<div class="cards">
    <div class="paper movable">
        <h1><a href="{{ url_for('setup.home') }}">Tournament Setup</a></h1>
        <small>Add teams, tournaments, and matches</small>
    </div>
    <br>
    <div class="paper movable">
        <h1><a href="{{ url_for('scoring.home') }}">Scoring</a></h1>
        <small>Submit scores for your configured matches</small>
    </div>
    <div class="paper movable">
        <h1><a href="{{ url_for('scoring.leaderboard_home') }}">Leaderboard</a></h1>
        <small>Views teams in the tournament in an automatically refreshing table</small>
    </div>
</div>

{% endblock %}
\ No newline at end of file