예제 #1
0
 def post(self, request, tourney_uuid, prop_id):
     """
     A currently logged in user who is participating in the tournament can use
     this view to make a bet on an open proposition that they have not yet bet
     on.
     """
     bet_form = BetForm(request.POST)
     tourney = Tournament.objects.get(uuid=tourney_uuid)
     prop = Proposition.objects.get(id=prop_id, tournament=tourney)
     if bet_form.is_valid():
         form_prop = bet_form.cleaned_data["proposition"]
         if prop != form_prop:
             return HttpResponseForbidden("Illegal bet form.")
         player = bet_form.cleaned_data["created_by"]
         if not player.is_user_player(request.user):
             return HttpResponseForbidden("Player and user differ.")
         bet = bet_form.save(commit=False)
         prop.make_bet(bet)
         messages.add_message(self.request, messages.SUCCESS, "Bet made.")
         return redirect("tournament-details", tourney.uuid)
     else:
         return render(self.request, self.template_name, {
             "form": form,
             "tourney": tourney,
             "prop": prop
         })
예제 #2
0
    def get(self, request, tourney_uuid, prop_id):
        # Only users should be able to get here.
        tourney = Tournament.objects.get(uuid=tourney_uuid)

        prop = Proposition.objects.get(id=prop_id, tournament=tourney)
        form = BetForm(initial={"credits": 1.0, "proposition": prop})
        return render(self.request, self.template_name, {
            "form": form,
            "tourney": tourney,
            "prop": prop
        })
예제 #3
0
파일: views.py 프로젝트: Briegguyon/betwit
 def post(self, request, username):
   form = BetForm(self.request.POST)
   if form.is_valid():
     ser	= User.objects.get(username=username)
     match     = Match.objects.get(id=form.cleaned_data['match'])
     print 'form = %r' % form
     bet	= Bet(
                   user 	= user,
                   match 	= match,
                   scoreA	= form.cleaned_data['scoreA'],
                   scoreB 	= form.cleaned_data['scoreB'],
                   triesA 	= form.cleaned_data['triesA'],
                   triesB 	= form.cleaned_data['triesB'],
                   card	= form.cleaned_data['card'],
                   drop_goal   = form.cleaned_data['drop_goal'],
                   fight       = form.cleaned_data['fight'],
                   created_date= timezone.now()
                 )
     bet.save()
     return HttpResponseRedirect('/user/'+username+'/')
   else:
     print 'form = %r' % form
     return render(request, 'betcup.html', {'form': form})
예제 #4
0
 def post(self, request, tourney_uuid, prop_id):
     """
     A currently logged in user who is participating in the tournament can use
     this view to make a bet on an open proposition that they have not yet bet
     on.
     """
     bet_form = BetForm(request.POST)
     tourney = Tournament.objects.get(uuid=tourney_uuid)
     prop = Proposition.objects.get(id=prop_id, tournament=tourney)
     if bet_form.is_valid():
         form_prop = bet_form.cleaned_data["proposition"]
         if prop != form_prop:
             return HttpResponseForbidden("Illegal bet form.")
         player = bet_form.cleaned_data["created_by"]
         if not player.is_user_player(request.user):
             return HttpResponseForbidden("Player and user differ.")
         bet = bet_form.save(commit=False)
         prop.make_bet(bet)
         messages.add_message(self.request, messages.SUCCESS, "Bet made.")
         return redirect("tournament-details", tourney.uuid)
     else:
         return render(self.request, self.template_name, {"form": form,
                                                         "tourney": tourney,
                                                         "prop": prop})