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.") if not tourney.is_open: return HttpResponseForbidden("This tournament is closed.") form = PropositionForm(request.POST) game_schedule_form = GameScheduleForm(request.POST) if form.is_valid() and game_schedule_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.") game = form.save(commit=False) schedule = game_schedule_form.save(commit=True) game.schedule = schedule game.save() messages.add_message(self.request, messages.SUCCESS, "Proposition added.") return redirect("add-proposition", tourney.uuid) else: return render(self.request, self.template_name, {"tourney": tourney, "add_prop_form": form, "schedule_form": game_schedule_form, "user_is_admin": True})
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.") if not tourney.is_open: return HttpResponseForbidden("This tournament is closed.") form = PropositionForm(request.POST) game_schedule_form = GameScheduleForm(request.POST) if form.is_valid() and game_schedule_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.") game = form.save(commit=False) schedule = game_schedule_form.save(commit=True) game.schedule = schedule game.save() messages.add_message(self.request, messages.SUCCESS, "Proposition added.") return redirect("add-proposition", tourney.uuid) else: return render( self.request, self.template_name, { "tourney": tourney, "add_prop_form": form, "schedule_form": game_schedule_form, "user_is_admin": True })
def get(self, request, tourney_uuid): """ Returns the details page for the tournament. """ tourney = Tournament.objects.get(uuid=tourney_uuid) user_is_admin = tourney.is_user_admin(request.user) if not user_is_admin: return HttpResponseForbidden("Only the admin can view this page.") try: player = Player.objects.get(tournament=tourney, user=request.user) except: player = None join_form = TournamentForm(initial={"uuid": tourney.uuid}) tournament_form = TournamentForm(initial={"uuid": tourney.uuid}) add_prop_form = PropositionForm(initial={"tournament": tourney.id}) game_schedule_form = GameScheduleForm() propositions = Proposition.objects.filter(tournament=tourney) return render( self.request, self.template_name, { "tourney": tourney, "tournament_form": tournament_form, "propositions": propositions, "game_schedule_form": game_schedule_form, "player": player, "join_form": join_form, "user_is_admin": user_is_admin, "add_prop_form": add_prop_form, })
def get(self, request, tourney_uuid): 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.") if not tourney.is_open: return HttpResponseForbidden("This tournament is closed.") schedule_form = ScheduleForm(request.GET) if schedule_form.is_valid(): json_response = DatabaseSchedule().get(self.request).content games = json.loads(json_response) else: games = None add_prop_form = PropositionForm(initial={"tournament": tourney.id}) game_schedule_form = GameScheduleForm() GameDatabaseFormset = formset_factory(GameDatabaseForm, extra=0) if games: formset = GameDatabaseFormset(initial=games["games"]) else: formset = None game_seasons = GameSeason.objects.all() return render( self.request, self.template_name, { "tourney": tourney, "now": datetime.datetime.now(), "add_prop_form": add_prop_form, "user_is_admin": True, "game_seasons": game_seasons, "game_schedule_form": game_schedule_form, "games": games, "formset": formset })
def get(self, request, tourney_uuid): """ Returns the details page for the tournament. """ tourney = Tournament.objects.get(uuid=tourney_uuid) if not request.user.is_authenticated(): return render(self.request, self.player_landing, {"tourney": tourney}) try: player = Player.objects.get(tournament=tourney, user=request.user) except: player = None user_is_admin = tourney.is_user_admin(request.user) join_form = TournamentForm(initial={"uuid":tourney.uuid}) if not player and not user_is_admin: return render(self.request, self.tourney_advert, {"tourney": tourney, "join_form": join_form}) tournament_form = TournamentForm(initial={"uuid":tourney.uuid}) add_prop_form = PropositionForm(initial={"tournament":tourney.id}) propositions = Proposition.objects.filter(tournament=tourney) bettable_props = propositions.exclude(bet__created_by=player).filter(is_open=True) bets = Bet.objects.filter(proposition__tournament=tourney, created_by=player).order_by("-proposition__paid_on") return render(self.request, self.template_name, {"tourney": tourney, "bettable_props": bettable_props, "tournament_form": tournament_form, "propositions": propositions, "player": player, "user_is_admin": user_is_admin, "add_prop_form": add_prop_form, "bets": bets})