-
-
Notifications
You must be signed in to change notification settings - Fork 864
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
103 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters