示例#1
0
def player_edit(request,player_id=0,template="admin/player/edit.tpl"):
    player = Player.get_by_id(player_id)
    if request.method == "GET":
        return render_response(template,player=player)
    elif request.method == "POST":
        form = PlayerForm(request.POST)
        if form.is_valid():
            level = form.cleaned_data['level']
            ep = form.cleaned_data['ep']
            sp = form.cleaned_data['sp']
            vm = form.cleaned_data['vm']
            grm = form.cleaned_data['grm']
            brm = form.cleaned_data['brm']
            try:
                player.level = level
                player.ep = ep
                player.sp = sp
                player.vm = vm
                player.grm = grm
                player.brm = brm
                player.save()
            except Exception,e:
                if config.debug:
                    print e
            else:
                return HttpResponse("<script type='text/javascript'>window.top.right.location.reload();window.top.art.dialog({id:'player_edit'}).close();</script>")
示例#2
0
def player_add(request,template="admin/player/add.tpl"):
    if request.method == "GET":
        return render_response(template)
    elif request.method == "POST":
        form = PlayerForm(request.POST)
        if form.is_valid():
            level = form.cleaned_data['level']
            update_need_xp = form.cleaned_data['update_need_xp']
            energy = form.cleaned_data['energy']
            try:
                player = Player.objects.create(level=level,update_need_xp=update_need_xp,
                                              energy=energy)
                player.save()
            except Exception,e:
                if config.debug:
                    print e
            else:
                return HttpResponse("<script type='text/javascript'>window.top.right.location.reload();window.top.art.dialog({id:'player_add'}).close();</script>")