Ejemplo n.º 1
0
def weapon_edit(request,weapon_id=0,template="admin/card/weapon/edit.tpl"):
    weapon = Card.get_card("Weapon",weapon_id)
    if request.method == "GET":
        return render_response(template,weapon=weapon)
    elif request.method == "POST":
        form = WeaponForm(request.POST)
        if form.is_valid():
            name = form.cleaned_data['name']
            rarity = form.cleaned_data['rarity']
            description = form.cleaned_data['description']
            rebirth_max = form.cleaned_data['rebirth_max']
            is_unlock = form.cleaned_data['is_unlock']
            image = form.cleaned_data['image']
            attack = form.cleaned_data['attack']
            try:
                edit_card = False
                if (rarity != weapon.rarity) or (name != weapon.name):
                    edit_card = True
                weapon.name = name
                weapon.rarity = rarity
                weapon.description = description
                weapon.attack = attack
                weapon.rebirth_max = rebirth_max
                weapon.is_unlock = is_unlock
                if image:
                    weapon.image = image
                weapon.save()
                if edit_card:
                    _edit_card(weapon,"Weapon")
            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:'weapon_edit'}).close();</script>")
Ejemplo n.º 2
0
def weapon_add(request,template="admin/card/weapon/add.tpl"):
    if request.method == "GET":
        return render_response(template)
    elif request.method == "POST":
        form = WeaponForm(request.POST)
        if form.is_valid():
            name = form.cleaned_data['name']
            rarity = form.cleaned_data['rarity']
            description = form.cleaned_data['description']
            rebirth_max = form.cleaned_data['rebirth_max']
            is_unlock = form.cleaned_data['is_unlock']
            image = form.cleaned_data['image']
            attack = form.cleaned_data['attack']
            try:
                weapon = Weapon.objects.create(name=name,rarity=rarity,description=description,attack=attack,
                                               rebirth_max=rebirth_max,is_unlock=is_unlock,
                                               image=image)
                weapon.save()
                _add_card(weapon,"武器","Weapon")
            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:'weapon_add'}).close();</script>")