Skip to content

Commit

Permalink
refactor: removes deprecated models match and round
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelobbfonseca committed Nov 27, 2023
1 parent 2e6187e commit 71d6a8c
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 76 deletions.
Original file line number Diff line number Diff line change
@@ -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',
),
]
49 changes: 0 additions & 49 deletions eliminationtournaments/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
9 changes: 1 addition & 8 deletions eliminationtournaments/serializers.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down Expand Up @@ -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')
20 changes: 1 addition & 19 deletions eliminationtournaments/tests/models.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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)

0 comments on commit 71d6a8c

Please sign in to comment.