~muirrum/comortas

1dcd924ec281c2464e9269b3cc153b4aa702eeb5 — Cara Salter 3 years ago 0a34d68 0.2.0
Implement tournament deletion
M fllscoring/models.py => fllscoring/models.py +2 -2
@@ 26,7 26,7 @@ class Tournaments(db.Model):

class Team(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    tournament = db.Column(db.Integer, ForeignKey("tournaments.id"), nullable=False, index=True)
    tournament = db.Column(db.Integer, ForeignKey("tournaments.id", ondelete="CASCADE", onupdate="CASCADE"), nullable=False, index=True)
    team_number = db.Column(db.Integer, nullable=False, unique=True)
    team_name = db.Column(db.String, nullable=False, default="No Name")
    team_town = db.Column(db.String, nullable=False, default="No Town")


@@ 36,6 36,6 @@ class Team(db.Model):

class MatchScore(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    tournament = db.Column(db.Integer, ForeignKey("tournaments.id"))
    tournament = db.Column(db.Integer, ForeignKey("tournaments.id", ondelete="CASCADE"))
    team = db.Column(db.Integer, ForeignKey("team.id"))
    score = db.Column(MutableDict().as_mutable(JSONB))
\ No newline at end of file

M fllscoring/setup/__init__.py => fllscoring/setup/__init__.py +14 -1
@@ 1,4 1,4 @@
from flask import Blueprint, render_template, redirect, url_for, flash, abort
from flask import Blueprint, render_template, redirect, url_for, flash, abort, request

from flask_login import login_required, current_user



@@ 43,6 43,19 @@ def manage_tournament(id):
        abort(404)
    return render_template("setup/tournament_mgmt.html", title=f"Update tournament {tournament.tournament_name}", tournament=tournament, teams=teams)

@bp.route("/delete_tournament/<int:id>", methods=["GET", "POST"])
@login_required
def delete_tournament(id):
    tournament = Tournaments.query.filter_by(id=id).first()
    if tournament is None:
        abort(404)
    if request.method == 'POST':
        db.session.delete(tournament)
        db.session.commit()
        return redirect(url_for('setup.home'))
    
    return render_template("setup/delete_tournament.html", title=f"Delete tournament {tournament.tournament_name}", tournament=tournament)

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

A fllscoring/templates/setup/delete_tournament.html => fllscoring/templates/setup/delete_tournament.html +11 -0
@@ 0,0 1,11 @@
{% extends 'base.html' %}

{% block content %}
<h1>Are you sure you want to delete this tournament?</h1>
<span class="hbar">
    <a href="url_for('setup.manage_tournament', id=tournament.id) }}" class="paper movable">No</a>
    <form method="POST">
        <input type="submit" class="paper movable accent" value="Yes">
    </form>
</span>
{% endblock %}
\ No newline at end of file

M fllscoring/templates/setup/tournament_mgmt.html => fllscoring/templates/setup/tournament_mgmt.html +5 -1
@@ 1,8 1,12 @@
{% extends 'base.html' %}

{% block content %}
<h1>{{ tournament.tournament_name.capitalize() }} Overview</h1>
<span class="hbar">
    <h1>{{ tournament.tournament_name }} Overview</h1>
    <a href="{{ url_for('setup.delete_tournament', id=tournament.id) }}" class="paper movable accent">Delete</a>
</span>
    <p>Not much here...</p>

<hr>
<span class="hbar">
    <h1>Teams</h1>

A migrations/versions/616627625894_set_cascade.py => migrations/versions/616627625894_set_cascade.py +34 -0
@@ 0,0 1,34 @@
"""Set cascade

Revision ID: 616627625894
Revises: bed7e505df9b
Create Date: 2021-04-24 10:06:14.856907

"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = '616627625894'
down_revision = 'bed7e505df9b'
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_constraint('match_score_tournament_fkey', 'match_score', type_='foreignkey')
    op.create_foreign_key(None, 'match_score', 'tournaments', ['tournament'], ['id'], ondelete='CASCADE')
    op.drop_constraint('team_tournament_fkey', 'team', type_='foreignkey')
    op.create_foreign_key(None, 'team', 'tournaments', ['tournament'], ['id'], onupdate='CASCADE', ondelete='CASCADE')
    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_constraint(None, 'team', type_='foreignkey')
    op.create_foreign_key('team_tournament_fkey', 'team', 'tournaments', ['tournament'], ['id'])
    op.drop_constraint(None, 'match_score', type_='foreignkey')
    op.create_foreign_key('match_score_tournament_fkey', 'match_score', 'tournaments', ['tournament'], ['id'])
    # ### end Alembic commands ###