def populate_objects(self): self.debate = self.object = self.get_object() self.ballotsub = BallotSubmission( debate=self.debate, submitter=self.request.user, submitter_type=BallotSubmission.SUBMITTER_TABROOM, ip_address=get_ip_address(self.request)) t = self.get_tournament() if t.pref('ballots_per_debate') == 'per-adj' and \ not self.debate.adjudicators.has_chair: messages.error( self.request, _("Whoops! The debate %(debate)s doesn't have a chair, " "so you can't enter results for it.") % {'debate': self.debate.matchup}) return redirect_round('results-round-list', self.ballotsub.debate.round) if not (t.pref('draw_side_allocations') == 'manual-ballot' and t.pref('teams_in_debate') == 'two') and not self.debate.sides_confirmed: messages.error( self.request, _("Whoops! The debate %(debate)s doesn't have its " "sides confirmed, so you can't enter results for it.") % {'debate': self.debate.matchup}) return redirect_round('results-round-list', self.ballotsub.debate.round)
def post(self, request, *args, **kwargs): # Advance relative to the round of the view, not the current round, so # that in times of confusion, going back then clicking again won't advance # twice. next_round = self.tournament.round_set.filter(seq__gt=self.round.seq).order_by('seq').first() if next_round: self.tournament.current_round = next_round self.tournament.save() self.log_action(round=next_round, content_object=next_round) if (next_round.stage == Round.STAGE_ELIMINATION and self.round.stage == Round.STAGE_PRELIMINARY): messages.success(request, _("The current round has been advanced to %(round)s. " "You've made it to the end of the preliminary rounds! Congratulations! " "The next step is to generate the break.") % {'round': next_round.name}) return redirect_tournament('breakqual-index', self.tournament) else: messages.success(request, _("The current round has been advanced to %(round)s. " "Woohoo! Keep it up!") % {'round': next_round.name}) return redirect_round('availability-index', next_round) else: messages.error(request, _("Whoops! Could not advance round, because there's no round " "after this round!")) return super().post(request, *args, **kwargs)
def formset_valid(self, formset): motions = formset.save(commit=False) round = self.round for i, motion in enumerate(motions, start=1): if not self.tournament.pref('enable_motions'): motion.seq = i motion.round = round motion.save() self.log_action(content_object=motion) for motion in formset.deleted_objects: motion.delete() count = len(motions) if not self.tournament.pref('enable_motions') and count == 1: messages.success(self.request, _("The motion has been saved.")) elif count > 0: messages.success(self.request, ngettext("%(count)d motion has been saved.", "%(count)d motions have been saved.", count) % {'count': count}) count = len(formset.deleted_objects) if count > 0: messages.success(self.request, ngettext("%(count)d motion has been deleted.", "%(count)d motions have been deleted.", count) % {'count': count}) return redirect_round('draw-display', round)
def post(self, request, *args, **kwargs): # Advance relative to the round of the view, not the current round, so # that in times of confusion, going back then clicking again won't advance # twice. next_round = self.tournament.round_set.filter( seq__gt=self.round.seq).order_by('seq').first() if next_round: self.tournament.current_round = next_round self.tournament.save() self.log_action(round=next_round, content_object=next_round) if (next_round.stage == Round.STAGE_ELIMINATION and self.round.stage == Round.STAGE_PRELIMINARY): messages.success( request, _("The current round has been advanced to %(round)s. " "You've made it to the end of the preliminary rounds! Congratulations! " "The next step is to generate the break.") % {'round': next_round.name}) return redirect_tournament('breakqual-index', self.tournament) else: messages.success( request, _("The current round has been advanced to %(round)s. " "Woohoo! Keep it up!") % {'round': next_round.name}) return redirect_round('availability-index', next_round) else: messages.error( request, _("Whoops! Could not advance round, because there's no round " "after this round!")) return super().post(request, *args, **kwargs)
def motions_assign(request, round): class MyModelChoiceField(ModelMultipleChoiceField): def label_from_instance(self, obj): return "D%s @ %s" % ( obj.name, obj.venue_group.short_name, ) class ModelAssignForm(ModelForm): divisions = MyModelChoiceField( widget=CheckboxSelectMultiple, queryset=Division.objects.filter(tournament=round.tournament).order_by('venue_group')) class Meta: model = Motion fields = ("divisions",) motion_form_set = modelformset_factory(Motion, ModelAssignForm, extra=0, fields=['divisions']) if request.method == 'POST': formset = motion_form_set(request.POST) formset.save() # Should be checking for validity but on a deadline and was buggy if 'submit' in request.POST: return redirect_round('draw', round) formset = motion_form_set(queryset=Motion.objects.filter(round=round)) return render(request, "assign.html", dict(formset=formset))
def draw_regenerate(request, round): from .dbutils import delete_round_draw ActionLogEntry.objects.log(type=ActionLogEntry.ACTION_TYPE_DRAW_REGENERATE, user=request.user, round=round, tournament=round.tournament) delete_round_draw(round) return redirect_round('draw', round)
def post(self, request, *args, **kwargs): self.round.completed = True self.round.save() self.log_action(round=self.round, content_object=self.round) incomplete_rounds = self.tournament.round_set.filter(completed=False) if not incomplete_rounds.exists(): messages.success(request, _("%(round)s has been marked as completed. " "All rounds are now completed, so you're done with the tournament! " "Congratulations!") % {'round': self.round.name}) return redirect_tournament('tournament-admin-home', self.tournament) elif not self.round.next: messages.success(request, _("%(round)s has been marked as completed. " "That's the last round in that sequence! Going back to the first " "round that hasn't been marked as completed.") % {'round': self.round.name}) # guaranteed to exist, otherwise the first 'if' statement would have been false round_for_redirect = incomplete_rounds.order_by('seq').first() return redirect_round('availability-index', round_for_redirect) if (self.round.stage == Round.STAGE_PRELIMINARY and self.round.next.stage == Round.STAGE_ELIMINATION): incomplete_prelim_rounds = incomplete_rounds.filter(stage=Round.STAGE_PRELIMINARY) if not incomplete_prelim_rounds.exists(): messages.success(request, _("%(round)s has been marked as completed. " "You've made it to the end of the preliminary rounds! Congratulations! " "The next step is to generate the break.") % {'round': self.round.name}) return redirect_tournament('breakqual-index', self.tournament) else: messages.success(request, _("%(round)s has been marked as completed. " "That was the last preliminary round, but one or more preliminary " "rounds are still not completed. Going back to the first incomplete " "preliminary round.") % {'round': self.round.name}) round_for_redirect = incomplete_prelim_rounds.order_by('seq').first() return redirect_round('availability-index', round_for_redirect) else: messages.success(request, _("%(this_round)s has been marked as completed. " "Moving on to %(next_round)s! Woohoo! Keep it up!") % { 'this_round': self.round.name, 'next_round': self.round.next.name, }) return redirect_round('availability-index', self.round.next)
def post(self, request, *args, **kwargs): debate_id = request.POST['debate_id'] try: debate = Debate.objects.get(round=self.get_round(), id=debate_id) except Debate.DoesNotExist: return HttpResponseBadRequest("Error: There isn't a debate in {} with id {}.".format(self.get_round().name, debate_id)) debate.result_status = self.new_status debate.save() return redirect_round('results-round-list', debate.round)
def get(self, request, *args, **kwargs): current_round = self.tournament.current_round if self.round != current_round: messages.error(self.request, "You are trying to advance from {this_round} but " "the current round is {current_round} — advance to {this_round} first!".format( this_round=self.round.name, current_round=current_round.name)) return redirect_round('results-round-list', current_round) else: return super().get(self, request, *args, **kwargs)
def populate_objects(self): self.debate = self.object = self.get_object() self.ballotsub = BallotSubmission(debate=self.debate, submitter=self.request.user, submitter_type=BallotSubmission.SUBMITTER_TABROOM, ip_address=get_ip_address(self.request)) if not self.debate.adjudicators.has_chair: messages.error(self.request, "Whoops! The debate %s doesn't have a chair, " "so you can't enter results for it." % self.debate.matchup) return redirect_round('results-round-list', self.ballotsub.debate.round)
def formset_valid(self, formset): motions = formset.save(commit=False) round = self.get_round() for motion in motions: motion.round = round motion.save() self.log_action(content_object=motion) for motion in formset.deleted_objects: motion.delete() return redirect_round('draw', self.get_round())
def formset_valid(self, formset): motions = formset.save(commit=False) round = self.get_round() for motion in motions: motion.round = round motion.save() self.log_action(content_object=motion) for motion in formset.deleted_objects: motion.delete() messages.success(self.request, 'The motions have been saved.') return redirect_round('motions-edit', round)
def post(self, request, *args, **kwargs): active_teams = Team.objects.filter(debateteam__debate__round=self.round).prefetch_related('speaker_set') populate_win_counts(active_teams) try: send_standings_emails(self.tournament, active_teams, request, self.round) except (ConnectionError, SMTPException): messages.error(request, _("Team point emails could not be sent.")) else: messages.success(request, _("Team point emails have been sent to the speakers.")) return redirect_round('tournament-advance-round-check', self.round)
def get(self, request, *args, **kwargs): current_round = self.tournament.current_round if self.round != current_round: messages.error( self.request, "You are trying to advance from {this_round} but " "the current round is {current_round} — advance to {this_round} first!" .format(this_round=self.round.name, current_round=current_round.name)) return redirect_round('results-round-list', current_round) else: return super().get(self, request, *args, **kwargs)
def confirm_draw(request, round): if round.draw_status != round.STATUS_DRAFT: return HttpResponseBadRequest("Draw status is not DRAFT") round.draw_status = round.STATUS_CONFIRMED round.save() ActionLogEntry.objects.log(type=ActionLogEntry.ACTION_TYPE_DRAW_CONFIRM, user=request.user, round=round, tournament=round.tournament) return redirect_round('draw', round)
def unrelease_draw(request, round): if round.draw_status != round.STATUS_RELEASED: return HttpResponseBadRequest("Draw status is not RELEASED") round.draw_status = round.STATUS_CONFIRMED round.save() ActionLogEntry.objects.log(type=ActionLogEntry.ACTION_TYPE_DRAW_UNRELEASE, user=request.user, round=round, tournament=round.tournament) return redirect_round('draw', round)
def post(self, request, *args, **kwargs): active_teams = Team.objects.filter(debateteam__debate__round=self.round ).prefetch_related('speaker_set') populate_win_counts(active_teams) try: send_standings_emails(self.tournament, active_teams, request, self.round) except (ConnectionError, SMTPException): messages.error(request, _("Team point emails could not be sent.")) else: messages.success( request, _("Team point emails have been sent to the speakers.")) return redirect_round('tournament-advance-round-check', self.round)
def show_message(self, count, deleted): if not self.tournament.pref('enable_motions') and count == 1: messages.success(self.request, _("The motion has been saved.")) elif count > 0: messages.success( self.request, ngettext("%(count)d motion has been saved.", "%(count)d motions have been saved.", count) % {'count': count}) if deleted > 0: messages.success( self.request, ngettext("%(count)d motion has been deleted.", "%(count)d motions have been deleted.", deleted) % {'count': deleted}) return redirect_round('draw-display', self.round)
def post(self, request, *args, **kwargs): tournament = self.get_tournament() # Advance relative to the round of the view, not the current round, so # that in times of confusion, going back then clicking again won't advance # twice. next_round = self.get_round().next if next_round: tournament.current_round = next_round tournament.save() messages.success( request, "Advanced the current round. The current round is now %s. " "Woohoo! Keep it up!" % next_round.name, ) self.log_action(round=next_round, content_object=next_round) return redirect_round("availability-index", next_round) else: messages.error(request, "Whoops! Could not advance round, because there's no round " "after this round!") return super().post(request, *args, **kwargs)
def apply_schedule(request, round): import datetime debates = Debate.objects.filter(round=round) for debate in debates: division = debate.teams[0].division if division and division.time_slot: date = request.POST[str(division.venue_group.id)] if date: time = "%s %s" % (date, division.time_slot) try: debate.time = datetime.datetime.strptime(time, "%Y-%m-%d %H:%M:%S") # Chrome except ValueError: debate.time = datetime.datetime.strptime(time, "%d/%m/%Y %H:%M:%S") # Others debate.save() messages.success(request, "Applied schedules to debates") return redirect_round('draw', round)
def formset_valid(self, formset): formset.save() # Should be checking for validity but on a deadline and was buggy messages.success(self.request, 'Those motion assignments have been saved.') return redirect_round('motions-edit', self.round)