From 71d6a8c18fd403e683f001c1333ccc9f301164c0 Mon Sep 17 00:00:00 2001 From: marcelobbfonseca Date: Mon, 27 Nov 2023 10:01:31 -0300 Subject: [PATCH] refactor: removes deprecated models match and round --- ...nd_tournament_delete_match_delete_round.py | 23 +++++++++ eliminationtournaments/models.py | 49 ------------------- eliminationtournaments/serializers.py | 9 +--- eliminationtournaments/tests/models.py | 20 +------- 4 files changed, 25 insertions(+), 76 deletions(-) create mode 100644 eliminationtournaments/migrations/0016_remove_round_tournament_delete_match_delete_round.py diff --git a/eliminationtournaments/migrations/0016_remove_round_tournament_delete_match_delete_round.py b/eliminationtournaments/migrations/0016_remove_round_tournament_delete_match_delete_round.py new file mode 100644 index 0000000..0c4d955 --- /dev/null +++ b/eliminationtournaments/migrations/0016_remove_round_tournament_delete_match_delete_round.py @@ -0,0 +1,23 @@ +# Generated by Django 4.2 on 2023-11-27 13:00 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('eliminationtournaments', '0015_alter_tournament_match_ends'), + ] + + operations = [ + migrations.RemoveField( + model_name='round', + name='tournament', + ), + migrations.DeleteModel( + name='Match', + ), + migrations.DeleteModel( + name='Round', + ), + ] diff --git a/eliminationtournaments/models.py b/eliminationtournaments/models.py index 3570fde..abebb21 100644 --- a/eliminationtournaments/models.py +++ b/eliminationtournaments/models.py @@ -79,30 +79,6 @@ def __repr__(self) -> str: def __str__(self) -> str: return "<{},{}>".format(self.id, self.name) -class Round(models.Model): - round_number = models.IntegerField(default=0) - tournament = models.ForeignKey(Tournament, on_delete=models.CASCADE) - # matches = models.ManyToOneRel - - @staticmethod - def from_entity(entity: RoundEntity) -> 'Round': - return Round( - round_number= entity.round_number, - tournament_id= entity.tournament_id, - matches_ids= entity.matches_ids - ) - - def to_entity(self) -> RoundEntity: - return RoundEntity( - self.id, - self.round_number, - self.tournament.id, - matches_ids= self.matches.values_list('id', flat=True) - ) - - def __str__(self) -> str: - return "<{},{},round: {}>".format(self.id, self.tournament.name, self.round) - class Player(models.Model): avatar = models.CharField(max_length=255) @@ -189,31 +165,6 @@ def __str__(self) -> str: return "<{},{}, depth: {}, {}, left: {},next: {}, right: {}>".format(self.id, self.tournament.name, self.depth, player, left, next, right) -class Match(models.Model): - position_one = models.ForeignKey( - Position, null=True, blank=True,related_name='positions_one' , on_delete=models.SET_NULL) - position_two = models.ForeignKey( - Position, null=True, blank=True,related_name='positions_two', on_delete=models.SET_NULL) - disabled = models.BooleanField(default=False) - voted = models.BooleanField(default=False) - round = models.ForeignKey(Round, on_delete=models.CASCADE) - - @staticmethod - def from_entity(entity: MatchEntity) -> 'Match': - return Match( - position_one=entity.position_one, - position_two=entity.position_two, - disabled=entity.disabled, - round_id=entity.round_id, - ) - - def to_entity(self) -> MatchEntity: - return MatchEntity( - self.position_one.id, - self.position_two.id, - self.disabled, - self.round.id, - ) models.signals.post_save.connect(start_tournament, sender=Tournament) # models.signals.post_save.connect(create_brackets, sender=Tournament) \ No newline at end of file diff --git a/eliminationtournaments/serializers.py b/eliminationtournaments/serializers.py index ef74697..8ab8c97 100644 --- a/eliminationtournaments/serializers.py +++ b/eliminationtournaments/serializers.py @@ -1,5 +1,5 @@ from rest_framework import serializers -from .models import Tournament, Player, Position, Match +from .models import Tournament, Player, Position from eliminationtournaments.handlers.create_brackets_handler import CreateBracketsHandler class PlayerSerializer(serializers.ModelSerializer): @@ -46,10 +46,3 @@ def create(self, data): def get_position_set(self, instance): positions = instance.position_set.all().order_by('bracket_index') return PositionSerializer(positions, many=True, read_only=True).data - -class MatchSerializer(serializers.HyperlinkedModelSerializer): - position_one = PositionSerializer(read_only=True) - position_two = PositionSerializer(read_only=True) - class Meta: - model = Match - fields = ('position_one', 'position_two' 'disabled', 'voted', 'round') diff --git a/eliminationtournaments/tests/models.py b/eliminationtournaments/tests/models.py index e5070ef..f5214e8 100644 --- a/eliminationtournaments/tests/models.py +++ b/eliminationtournaments/tests/models.py @@ -1,5 +1,5 @@ from django.test import TestCase -from eliminationtournaments.models import Tournament, Round, Player, Position, Match +from eliminationtournaments.models import Tournament, Player, Position from eliminationtournaments.inner_layer.entities import TournamentEntity class TournamentTest(TestCase): @@ -31,11 +31,6 @@ def test_to_entity(self): self.assertEqual(entity.id, tournament.id) -class RoundTest(TestCase): - def test_create(self): - tournament = Tournament.objects.create() - round = Round.objects.create(round_number=0, tournament=tournament) - self.assertIsNotNone(round.id) class PlayerTest(TestCase): def test_create(self): @@ -67,16 +62,3 @@ def test_next_node(self): self.assertIsNotNone(position.right_position.next_position()) self.assertEqual(position.right_position.next_position(), position) -class MatchTest(TestCase): - def test_create(self): - tournament=Tournament.objects.create() - position = Position.objects.create(depth=1, votes=0, tournament=tournament) - position_2 = Position.objects.create(depth=2, votes=0, tournament=tournament) - round = Round.objects.create(round_number=0, tournament=tournament) - matchup = Match.objects.create( - position_one=position, - position_two=position_2, - disabled=False, - round=round - ) - self.assertIsNotNone(matchup.id)