diff --git a/class_diagram.plantuml b/class_diagram.plantuml index 8e426f67..6e2adf9b 100644 --- a/class_diagram.plantuml +++ b/class_diagram.plantuml @@ -43,13 +43,20 @@ class Match{ id: int game_id: str date: str -tournament_id: str(None) +tournament_id: int|null } class Tournament{ id: int name: str matches_num: int +championship_id: int|null +} + +class Championship{ +id: int +name: str +final_tournament_id: int|null } User --> Bot @@ -60,4 +67,6 @@ Bots_challenged --> Challenge Bots_in_match --> Match Match --> Tournament Challenge --> Tournament +Tournament --> Championship +Championship --> Tournament @enduml \ No newline at end of file diff --git a/templates/base.html b/templates/base.html index 994a553f..bfdfa2d1 100644 --- a/templates/base.html +++ b/templates/base.html @@ -73,6 +73,7 @@ {% if user.is_staff %} Create Tournament Generate Tournament + Create Championship Pending Tournaments {% endif %} Tournaments History diff --git a/tournaments/admin.py b/tournaments/admin.py index c113fcde..6da9bfcb 100644 --- a/tournaments/admin.py +++ b/tournaments/admin.py @@ -2,8 +2,10 @@ from .models import ( Tournament, TournamentRegistration, + Championship, ) admin.site.register(Tournament) admin.site.register(TournamentRegistration) +admin.site.register(Championship) diff --git a/tournaments/common/tournament_utils.py b/tournaments/common/tournament_utils.py index ca2298f6..e0609e6c 100644 --- a/tournaments/common/tournament_utils.py +++ b/tournaments/common/tournament_utils.py @@ -47,6 +47,7 @@ def calculate_match_results_by_player(tournament_id): "total_match_lost": 0, "total_score": 0, }) + total_key = "" for bot_name, match_result, quantity in match_members_results: if match_result == WIN: total_key = "total_match_won" diff --git a/tournaments/forms.py b/tournaments/forms.py index aa07bb64..7f6a60ec 100644 --- a/tournaments/forms.py +++ b/tournaments/forms.py @@ -16,3 +16,9 @@ def setup_bots_choices(self): class TournamentGeneratorForm(forms.Form): tournament_name = forms.CharField(label='name', required=True) max_players = forms.IntegerField(label='maxPlayers', required=True) + + +class ChampionshipCreateForm(forms.Form): + championship_name = forms.CharField(label='name', required=True) + tournament_bots = forms.IntegerField(label='Finalist Bots per Tournament', required=True) + max_players = forms.IntegerField(label='maxPlayers', required=True) diff --git a/tournaments/migrations/0005_auto_20221017_1124.py b/tournaments/migrations/0005_auto_20221017_1124.py new file mode 100644 index 00000000..7b913359 --- /dev/null +++ b/tournaments/migrations/0005_auto_20221017_1124.py @@ -0,0 +1,27 @@ +# Generated by Django 2.2.20 on 2022-10-17 14:24 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('tournaments', '0004_tournament_status'), + ] + + operations = [ + migrations.CreateModel( + name='Championship', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('name', models.CharField(max_length=30)), + ('final_tournament', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, related_name='final_tournament', to='tournaments.Tournament')), + ], + ), + migrations.AddField( + model_name='tournament', + name='championship', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='tournaments.Championship'), + ), + ] diff --git a/tournaments/migrations/0006_championship_tournament_bots.py b/tournaments/migrations/0006_championship_tournament_bots.py new file mode 100644 index 00000000..308b5393 --- /dev/null +++ b/tournaments/migrations/0006_championship_tournament_bots.py @@ -0,0 +1,18 @@ +# Generated by Django 2.2.20 on 2022-10-17 15:11 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('tournaments', '0005_auto_20221017_1124'), + ] + + operations = [ + migrations.AddField( + model_name='championship', + name='tournament_bots', + field=models.IntegerField(default=0), + ), + ] diff --git a/tournaments/models.py b/tournaments/models.py index a8b2de18..4e919c98 100644 --- a/tournaments/models.py +++ b/tournaments/models.py @@ -2,6 +2,19 @@ from django.db import models +class Championship(models.Model): + name = models.CharField(max_length=30) + tournament_bots = models.IntegerField(default=0) + final_tournament = models.OneToOneField( + 'tournaments.Tournament', + on_delete=models.CASCADE, + related_name='final_tournament' + ) + + def __str__(self): + return f'{self.name} ({self.id})' + + class Tournament(models.Model): TOURNAMENT_PENDING_STATUS = 'pending' TOURNAMENT_ACTIVE_STATUS = 'active' @@ -14,6 +27,12 @@ class Tournament(models.Model): name = models.CharField(max_length=30) date_tournament = models.DateTimeField(auto_now_add=True, verbose_name='Date') + championship = models.ForeignKey( + Championship, + on_delete=models.CASCADE, + null=True, + blank=True, + ) status = models.CharField( max_length=8, choices=TOURNAMENT_STATUS, diff --git a/tournaments/templates/tournaments/create_championship.html b/tournaments/templates/tournaments/create_championship.html new file mode 100644 index 00000000..c574e563 --- /dev/null +++ b/tournaments/templates/tournaments/create_championship.html @@ -0,0 +1,21 @@ +{% extends "base.html" %} +{% load bootstrap4 %} +{% bootstrap_css %} +{% block page_content %} + +