def treasure_add(request,template="admin/card/treasure/add.tpl"): if request.method == "GET": return render_response(template) elif request.method == "POST": form = TreasureForm(request.POST) if form.is_valid(): name = form.cleaned_data['name'] rarity = form.cleaned_data['rarity'] description = form.cleaned_data['description'] # probability = form.cleaned_data['probability'] block = form.cleaned_data['block'] crit = form.cleaned_data['crit'] is_unlock = form.cleaned_data['is_unlock'] image = form.cleaned_data['image'] try: treasure = Treasure.objects.create(name=name,rarity=rarity,description=description, block = block,crit=crit, image=image,is_unlock=is_unlock) _add_card(treasure,"宝物","Treasure") treasure.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:'treasure_add'}).close();</script>")
def treasure_edit(request,treasure_id=0,template="admin/card/treasure/edit.tpl"): treasure = Card.get_card("Treasure",treasure_id) if request.method == "GET": return render_response(template,treasure=treasure) elif request.method == "POST": form = TreasureForm(request.POST) if form.is_valid(): name = form.cleaned_data['name'] rarity = form.cleaned_data['rarity'] description = form.cleaned_data['description'] # probability = form.cleaned_data['probability'] crit = form.cleaned_data['crit'] block = form.cleaned_data['block'] is_unlock = form.cleaned_data['is_unlock'] image = form.cleaned_data['image'] try: edit_card = False if (rarity != treasure.rarity) or (name != treasure.name): edit_card = True treasure.name = name treasure.rarity = rarity treasure.description = description # treasure.probability = probability treasure.crit = crit treasure.block = block treasure.is_unlock = is_unlock if image: treasure.image = image treasure.save() if edit_card: _edit_card(treasure,"Treasure") 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:'treasure_edit'}).close();</script>")