示例#1
0
    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
示例#2
0
 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
示例#3
0
    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,
            })
示例#4
0
    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})
示例#5
0
 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
示例#6
0
def create(request):
    if request.POST:
        form = TournamentForm(request.POST)
        if form.is_valid():
            tournament = form.save()
            #permission = Permission.objects.get(codename='change_tournament')
            user = request.user
            assign_perm('view_tournament', user, tournament)

            return HttpResponseRedirect('/team/create')
    else:
        form = TournamentForm()
    args = {}
    args.update(csrf(request))

    args['form'] = form

    return render_to_response('create_tournament.html', args)
示例#7
0
 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