def shield_edit(request,shield_id=0,template="admin/card/shield/edit.tpl"): shield = Card.get_card("Shield",shield_id) if request.method == "GET": return render_response(template,shield=shield) elif request.method == "POST": form = ShieldForm(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'] defence = form.cleaned_data['defence'] try: edit_card = False if (rarity != shield.rarity) or (name != shield.name): edit_card = True shield.name = name shield.rarity = rarity shield.description = description shield.rebirth_max = rebirth_max shield.is_unlock = is_unlock if image: shield.image = image shield.defence = defence shield.save() if edit_card: _edit_card(shield,"Shield") 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:'shield_edit'}).close();</script>")
def shield_add(request,template="admin/card/shield/add.tpl"): if request.method == "GET": return render_response(template) elif request.method == "POST": form = ShieldForm(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'] defence = form.cleaned_data['defence'] try: shield = Shield.objects.create(name=name,rarity=rarity,description=description, defence=defence,rebirth_max=rebirth_max, image=image,is_unlock=is_unlock) _add_card(shield,"防具","Shield") shield.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:'shield_add'}).close();</script>")