def post(self, request, tourney_uuid): """ Tries to add a proposition to the tournament. """ tourney = Tournament.objects.get(uuid=tourney_uuid) # Make sure that the user has admin rights for this tourney. if not tourney.is_user_admin(request.user): return HttpResponseForbidden("Only the tournament administrator can do that.") form = TournamentForm(request.POST) if form.is_valid(): # Make sure the input wasn't a lie. tourney2 = form.get_tournament() if not tourney == tourney2: return HttpResponseForbidden("Only the tournament administrator can do that.") if tourney.is_closable(): tourney.payout() messages.add_message(self.request, messages.SUCCESS, "Tournament paid out.") return redirect("tournament-details", tourney_uuid) else: messages.add_message(self.request, messages.ERROR, "There are still open propositions.") return redirect("tournament-details", tourney_uuid) else: return HttpResponseForbidden(str(form.errors)) # We should never get here. raise Http404
def post(self, request, tourney_uuid): """ Tries to add a proposition to the tournament. """ tourney = Tournament.objects.get(uuid=tourney_uuid) # Make sure that the user has admin rights for this tourney. if not tourney.is_user_admin(request.user): return HttpResponseForbidden( "Only the tournament administrator can do that.") form = TournamentForm(request.POST) if form.is_valid(): # Make sure the input wasn't a lie. tourney2 = form.get_tournament() if not tourney == tourney2: return HttpResponseForbidden( "Only the tournament administrator can do that.") if tourney.is_closable(): tourney.payout() messages.add_message(self.request, messages.SUCCESS, "Tournament paid out.") return redirect("tournament-details", tourney_uuid) else: messages.add_message(self.request, messages.ERROR, "There are still open propositions.") return redirect("tournament-details", tourney_uuid) else: return HttpResponseForbidden(str(form.errors)) # We should never get here. raise Http404
def post(self, request): """ Tries to add a player to a tournament. """ form = TournamentForm(request.POST) if form.is_valid(): uuid = form.cleaned_data["uuid"] tourney = form.get_tournament() if tourney.can_add_player(request.user): tourney.add_player(request.user) messages.add_message(self.request, messages.SUCCESS, "Joined tournament.") else: error_message = "Couldn't join the tournament. Do you have enough credits or have you already joined?" messages.add_message(self.request, messages.ERROR, error_message) return redirect("tournament-details", uuid) # The only way someone should get here is if they tampered with the form. raise Http404