Skip to content

Commit

Permalink
Merge branch 'hotfix/0.7.4'
Browse files Browse the repository at this point in the history
  • Loading branch information
philipbelesky committed Feb 28, 2016
2 parents 0f56891 + 7b89fe8 commit ce7658d
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 2 deletions.
9 changes: 9 additions & 0 deletions debate/management/commands/detach_all_adjs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from django.core.management.base import BaseCommand, CommandError
import debate.models as m

class Command(BaseCommand):
help = 'Detach all adjudicators from all tournaments'

def handle(self, *args, **options):

m.Adjudicator.objects.all().update(tournament=None)
57 changes: 57 additions & 0 deletions debate/management/commands/merge_rounds.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
from django.core.management.base import BaseCommand, CommandError
import debate.models as m

class Command(BaseCommand):
help = 'Merge two tournaments together'

def add_arguments(self, parser):
parser.add_argument('tournament', nargs=2, help="Tournament slugs")
parser.add_argument('round', help="Round seq number (must be same for both tournaments)")
parser.add_argument('target', help="Tournament to which debates will be copied")

def handle(self, *args, **options):

seq = options['round']

# Get target tournament
tournament = m.Tournament.objects.get(slug=options['target'])

# Create target round
if m.Round.objects.filter(tournament=tournament, seq=seq).exists():
response = raw_input("Warning: Round {} in tournament {} already exists. Delete? ".format(seq, tournament.slug))
if response != "yes":
raise CommandError("Cancelled by user.")
m.Round.objects.filter(tournament=tournament, seq=seq).delete()

target_round = m.Round(tournament=tournament, seq=seq, name=str(seq), abbreviation=str(seq),
draw_type=m.Round.DRAW_POWERPAIRED, stage=m.Round.STAGE_PRELIMINARY,
draw_status=m.Round.STATUS_CONFIRMED)
target_round.save()
tournament.current_round = target_round
tournament.save()

# Get source rounds
source_rounds = [m.Round.objects.get(tournament__slug=slug, seq=seq) for slug in options['tournament']]

# Copy debates
for source_round in source_rounds:
self.stdout.write("\n == " + str(source_round) + " == ")

for debate in source_round.debate_set.all():

# Make copy of debate teams first, so we can still iterate
# through them after saving debate
debate_teams = debate.debateteam_set.all()

# Debate
self.stdout.write("Copying " + str(debate))
debate.pk = None
debate.round = target_round
debate.save()

# DebateTeams
for debateteam in debate_teams:
self.stdout.write(" - " + str(debateteam))
debateteam.pk = None
debateteam.debate = debate
debateteam.save()
35 changes: 35 additions & 0 deletions debate/management/commands/split_adjallocations.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
from django.core.management.base import BaseCommand, CommandError
import debate.models as m

class Command(BaseCommand):
help = 'Copy adjudicator allocations back to respective debates'

def add_arguments(self, parser):
parser.add_argument('tournament', help="Merged tournament (no need to specify originals)")
parser.add_argument('round', help="Round seq number")

def handle(self, *args, **options):

seq = options['round']

# Get source tournament and round
tournament = m.Tournament.objects.get(slug=options['tournament'])
source_round = m.Round.objects.get(tournament=tournament, seq=seq)

for source_debate in source_round.debate_set.all():

target_debates = [d for d in m.Debate.objects.exclude(round__tournament=tournament).filter(
bracket=source_debate.bracket, room_rank=source_debate.room_rank) if
d.aff_team == source_debate.aff_team and d.neg_team == source_debate.neg_team]
if len(target_debates) > 1:
raise CommandError("Found more than one target debate for " + str(source_debate))
target_debate = target_debates[0]

self.stdout.write("Copying " + str(source_debate) + " to " + str(target_debate))

for source_debateadj in source_debate.debateadjudicator_set.all():
self.stdout.write(" - " + str(source_debateadj))
source_debateadj.pk = None
source_debateadj.debate = target_debate
source_debateadj.save()

2 changes: 1 addition & 1 deletion debate/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class Tournament(models.Model):
short_name = models.CharField(max_length=25, blank=True, null=True, default="", help_text="The name used in the menu")
seq = models.IntegerField(db_index=True, blank=True, null=True, help_text="The order in which tournaments are displayed")
slug = models.SlugField(unique=True, db_index=True, help_text="The sub-URL of the tournament; cannot have spaces")
current_round = models.ForeignKey('Round', null=True, blank=True,
current_round = models.ForeignKey('Round', null=True, blank=True, on_delete=models.SET_NULL,
related_name='tournament_', help_text="Must be set for the tournament to start! (Set after rounds are inputted)")
welcome_msg = models.TextField(blank=True, null=True, default="", help_text="Text/html entered here shows on the homepage")
release_all = models.BooleanField(default=False, help_text="This releases all results; do so only after the tournament is finished")
Expand Down
2 changes: 1 addition & 1 deletion debate/standings.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ def annotate_team_standings(teams, round=None, tournament=None, shuffle=False, r
if subranks:
_add_subranks(standings, attrgetter(precedence[0]), attrgetter(*precedence[1:]))
if division_ranks:
_add_division_ranks(standings, tournament.division_set.all())
_add_division_ranks(standings, attrgetter(*precedence), tournament.division_set.all())

return standings

0 comments on commit ce7658d

Please sign in to comment.