Beispiel #1
0
def secretbook_edit(request,secretbook_id=0,template="admin/card/secretbook/edit.tpl"):
    secretbook = Card.get_card("SecretBook",secretbook_id)
    if request.method == "GET":
        return render_response(template,secretbook=secretbook)
    elif request.method == "POST":
        form = SecretBookForm(request.POST)
        if form.is_valid():
            name = form.cleaned_data['name']
            rarity = form.cleaned_data['rarity']
            description = form.cleaned_data['description']
#             add_value_percent = form.cleaned_data['add_value_percent']
            attack_add_percent = form.cleaned_data['attack_add_percent']
            defence_add_percent = form.cleaned_data['defence_add_percent']
            is_unlock = form.cleaned_data['is_unlock']
            image = form.cleaned_data['image']
            try:
                edit_card = False
                if (rarity != secretbook.rarity) or (name != secretbook.name):
                    edit_card = True
                secretbook.name = name
                secretbook.rarity = rarity
                secretbook.description = description
                secretbook.attack_add_percent = attack_add_percent
                secretbook.defence_add_percent = defence_add_percent
                secretbook.is_unlock = is_unlock
                if image:
                    secretbook.image = image
                secretbook.save()
                if edit_card:
                    _edit_card(secretbook,"SecretBook")
            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:'secretbook_edit'}).close();</script>")
Beispiel #2
0
def secretbook_add(request,template="admin/card/secretbook/add.tpl"):
    if request.method == "GET":
        return render_response(template)
    elif request.method == "POST":
        form = SecretBookForm(request.POST)
        if form.is_valid():
            name = form.cleaned_data['name']
            rarity = form.cleaned_data['rarity']
            description = form.cleaned_data['description']
#             add_value_percent = form.cleaned_data['add_value_percent']
            attack_add_percent = form.cleaned_data['attack_add_percent']
            defence_add_percent = form.cleaned_data['defence_add_percent']
            is_unlock = form.cleaned_data['is_unlock']
            image = form.cleaned_data['image']
            try:
                secretbook = SecretBook.objects.create(name=name,rarity=rarity,description=description,
                                                       attack_add_percent=attack_add_percent,defence_add_percent=defence_add_percent,
                                                       image=image,is_unlock=is_unlock)
                _add_card(secretbook,"密卷","SecretBook")
                secretbook.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:'secretbook_add'}).close();</script>")