예제 #1
0
파일: views.py 프로젝트: oeegor/pong
def add_set_result(request, group_id, player1_id, player2_id):

    group = Group.objects.filter(pk=group_id)
    if group.stage.is_closed:
        return HttpResponseBadRequest("Unable to add result, stage is over")

    player1 = User.objects.get(pk=player1_id)
    player2 = User.objects.get(pk=player2_id)
    if request.method == 'GET':
        initial = {
            'player1': player1_id,
            'player2': player2_id,
            'player1_approved': player1_id == str(request.user.pk),
            'player2_approved': player2_id == str(request.user.pk),
        }
        if group_id:
            initial['group'] = group_id
        form = SetResultForm(
            initial=initial,
        )
        form.set_inputs(player1=player1, player2=player2)
        ctx = {
            'form': form
        }
        return ctx

    elif request.method == 'POST':
        post_data = deepcopy(request.POST)
        if post_data['group'] == '0':
            del post_data['group']
        form = SetResultForm(post_data)
        if str(request.user.pk) not in [player1_id, player2_id]:
            form.add_error(None, 'cannot set scores for not your games')
        if not form.is_valid():
            form.set_inputs(player1=player1, player2=player2)
            return {
                'form': form
            }
        new_result = form.save()
        if 'group' in post_data:
            new_result.send_group_notification(approve_base_url=build_approve_base_url(request))
        else:
            new_result.send_approve_notification(request.user.pk)

        if int(tournament_id):
            return HttpResponseRedirect(reverse('app-tournament', args=[tournament_id]))
        else:
            return HttpResponseRedirect(reverse('rating-list'))
예제 #2
0
파일: views.py 프로젝트: ekirill/pong
def add_set_result(request, tournament_id, group_id, player1_id, player2_id):
    if request.method == 'GET':
        initial = {
            'player1': player1_id,
            'player2': player2_id,
            'player1_approved': player1_id == str(request.user.pk),
            'player2_approved': player2_id == str(request.user.pk),
        }
        if group_id:
            initial['group'] = group_id
        form = SetResultForm(
            initial=initial,
        )
        form.set_hidden_inputs()
        ctx = {
            'player1': User.objects.get(pk=player1_id),
            'player2': User.objects.get(pk=player2_id),
            'form': form
        }
        return ctx

    elif request.method == 'POST':
        post_data = deepcopy(request.POST)
        if post_data['group'] == '0':
            del post_data['group']
        form = SetResultForm(post_data)
        if str(request.user.pk) not in [player1_id, player2_id]:
            form.add_error(None, 'cannot set scores for not your games')
        if not form.is_valid():
            form.set_hidden_inputs()
            return {
                'form': form
            }
        new_result = form.save()
        if 'group' in post_data:
            new_result.send_group_notification()
        else:
            new_result.send_approve_notification(request.user.pk)

        if int(tournament_id):
            return HttpResponseRedirect(reverse('app-tournament', args=[tournament_id]))
        else:
            return HttpResponseRedirect(reverse('rating-list'))
예제 #3
0
파일: views.py 프로젝트: ekirill/pong
def add_set_result(request, tournament_id, group_id, player1_id, player2_id):
    if request.method == 'GET':
        initial = {
            'player1': player1_id,
            'player2': player2_id,
            'player1_approved': player1_id == str(request.user.pk),
            'player2_approved': player2_id == str(request.user.pk),
        }
        if group_id:
            initial['group'] = group_id
        form = SetResultForm(initial=initial, )
        form.set_hidden_inputs()
        ctx = {
            'player1': User.objects.get(pk=player1_id),
            'player2': User.objects.get(pk=player2_id),
            'form': form
        }
        return ctx

    elif request.method == 'POST':
        post_data = deepcopy(request.POST)
        if post_data['group'] == '0':
            del post_data['group']
        form = SetResultForm(post_data)
        if str(request.user.pk) not in [player1_id, player2_id]:
            form.add_error(None, 'cannot set scores for not your games')
        if not form.is_valid():
            form.set_hidden_inputs()
            return {'form': form}
        new_result = form.save()
        if 'group' in post_data:
            new_result.send_group_notification()
        else:
            new_result.send_approve_notification(request.user.pk)

        if int(tournament_id):
            return HttpResponseRedirect(
                reverse('app-tournament', args=[tournament_id]))
        else:
            return HttpResponseRedirect(reverse('rating-list'))
예제 #4
0
def add_set_result(request, group_id, player1_id, player2_id):

    group = Group.objects.filter(pk=group_id)
    if group.stage.is_closed:
        return HttpResponseBadRequest("Unable to add result, stage is over")

    player1 = User.objects.get(pk=player1_id)
    player2 = User.objects.get(pk=player2_id)
    if request.method == 'GET':
        initial = {
            'player1': player1_id,
            'player2': player2_id,
            'player1_approved': player1_id == str(request.user.pk),
            'player2_approved': player2_id == str(request.user.pk),
        }
        if group_id:
            initial['group'] = group_id
        form = SetResultForm(initial=initial, )
        form.set_inputs(player1=player1, player2=player2)
        ctx = {'form': form}
        return ctx

    elif request.method == 'POST':
        post_data = deepcopy(request.POST)
        if post_data['group'] == '0':
            del post_data['group']
        form = SetResultForm(post_data)
        if str(request.user.pk) not in [player1_id, player2_id]:
            form.add_error(None, 'cannot set scores for not your games')
        if not form.is_valid():
            form.set_inputs(player1=player1, player2=player2)
            return {'form': form}
        new_result = form.save()
        if 'group' in post_data:
            new_result.send_group_notification(
                approve_base_url=build_approve_base_url(request))
        else:
            new_result.send_approve_notification(request.user.pk)

        if int(tournament_id):
            return HttpResponseRedirect(
                reverse('app-tournament', args=[tournament_id]))
        else:
            return HttpResponseRedirect(reverse('rating-list'))