Ejemplo n.º 1
0
def edit(request, game_id):
    game = get_object_or_404(Game, id=game_id)
    # if game.player == request.user or request.user.has_perm...:
    #     do something
    # else
    #     show error

    # if game.player != request.user:
    if not request.user.has_perm('rocketleague.change_game'):
        # messages.add_message(request, messages.WARNING, "You cannot edit other player's games!")
        messages.add_message(
            request, messages.WARNING,
            "You cannot edit any games because you are not a moderator!")
        return HttpResponseRedirect('/')

    if request.method == 'GET':
        form = GameForm(instance=game)
        context = {'form': form, 'game': game}
        return render(request, 'edit.html', context)

    elif request.method == 'POST':
        form = GameForm(request.POST, instance=game)
        if form.is_valid():
            updated_game = form.save()
            return HttpResponseRedirect(reverse('show', args=[game.id]))
            # return HttpResponseRedirect("games/{}".format(game.id))
        else:
            context = {'form': form, 'game': game}
            response = render(request, 'edit.html', context)
            return HttpResponse(response)
Ejemplo n.º 2
0
def create(request):
    form = GameForm(request.POST)
    if form.is_valid():
        new_game = form.save()
        return HttpResponseRedirect('/')
    else:
        context = {'form': form}
        response = render(request, 'new.html', context)
        return HttpResponse(response)
Ejemplo n.º 3
0
def create(request):
    form = GameForm(request.POST)
    if form.is_valid():
        new_game = form.save(commit=False)
        new_game.referee = request.user
        new_game.save()
        return HttpResponseRedirect(reverse('index'))
    else:
        context = {'form': form}
        response = render(request, 'new.html', context)
        return HttpResponse(response)
Ejemplo n.º 4
0
def create(request):
    # grab info from form
    # submit into database
    # new_game = Game.objects.create(request.POST)
    form = GameForm(request.POST)
    # check if submitted data is valid
    if form.is_valid():
        # if so, save and redirect to index page
        new_game = form.save()
        return HttpResponseRedirect('/')
    # if not, redirect to new page
    else:
        print(form.errors)
Ejemplo n.º 5
0
def edit(request, game_id):
    game = get_object_or_404(Game, id=game_id)
    if request.method == 'GET':
        form = GameForm(instance=game)
        context = {'form': form, 'game': game}
        return render(request, 'edit.html', context)

    elif request.method == 'POST':
        form = GameForm(request.POST, instance=game)
        if form.is_valid():
            updated_game = form.save()
            return HttpResponseRedirect(reverse('show', args=[game.id]))
        else:
            context = {'form': form, 'game': game}
            response = render(request, 'edit.html', context)
            return HttpResponse(response)