Beispiel #1
0
def game_edit(request, game_id):
    from goserver.forms import GameForm
    from goserver.models import Game

    # check if they are logged in and bail if they arent
    if request.user.is_anonymous():
        return HttpResponseRedirect('/accounts/login')

    # TODO *instead* of the check above, verify that the game belongs to the user we are logged in as
    # before allowing them to edit it!

    # load the existing game object
    game = Game.objects.get(pk = game_id)
    
    # update the game object if requested
    if request.method == 'POST':
        form = GameForm(request.POST, instance=game)                    
        if form.is_valid():
            game = form.save()
    
    form = GameForm(instance=game)

    return render(request,
                  'goserver_gameedit.html',
                  {"game_editForm": form, "Game": game})   
Beispiel #2
0
def game_create(request):
    from goserver.forms import GameForm
    from goserver.models import Game
    
    # check if they are logged in and bail if they arent
    if request.user.is_anonymous():
        return HttpResponseRedirect('/accounts/login')

    if request.method == 'POST':

        game = Game( Owner = request.user )
        form = GameForm(request.POST, instance=game)
        
        if form.is_valid():
            newgame = form.save()            
            return HttpResponseRedirect('/games/view/%d' % newgame.id)
    else:
        form = GameForm()

    return render(request,
                  'goserver_gamecreate.html',
                  {"GameForm": form})