Exemple #1
0
def general_add(request,template="admin/card/general/add.tpl"):
    group_list = Group.get_all()
    if request.method == "GET":
        return render_response(template,group_list=group_list)
    elif request.method == "POST":
        form = GeneralForm(request.POST)
        if form.is_valid():
            name = form.cleaned_data['name']
            rarity = form.cleaned_data['rarity']
            level = form.cleaned_data['level']
            group_id = form.cleaned_data['group_id']
            description = form.cleaned_data['description']
            attack = form.cleaned_data['attack']
            defence = form.cleaned_data['defence']
            rebirth_max = form.cleaned_data['rebirth_max']
            is_unlock = form.cleaned_data['is_unlock']
            image = form.cleaned_data['image']
            is_add_attack = form.cleaned_data['is_add_attack']
            is_for_init = form.cleaned_data['is_for_init']
            level_max = Card.get_level_max(rarity, 0);
            try:
                general = General.objects.create(name=name,rarity=rarity,level=level,
                                                 group_id=group_id,description=description,attack=attack,
                                                 defence=defence,rebirth_max=rebirth_max,is_unlock=is_unlock,
                                                 level_max=level_max,is_add_attack=is_add_attack,
                                                 is_for_init=is_for_init,image=image)
                general.save()
                _add_card(general,"武将","General")
            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:'general_add'}).close();</script>")
Exemple #2
0
def general_edit(request,general_id=0,template="admin/card/general/edit.tpl"):
    group_list = Group.get_all()
    general = Card.get_card("General",general_id)
    if request.method == "GET":
        return render_response(template,general=general,group_list=group_list)
    elif request.method == "POST":
        form = GeneralForm(request.POST)
        if form.is_valid():
            name = form.cleaned_data['name']
            rarity = form.cleaned_data['rarity']
            level = form.cleaned_data['level']
            group_id = form.cleaned_data['group_id']
            description = form.cleaned_data['description']
            attack = form.cleaned_data['attack']
            defence = form.cleaned_data['defence']
            rebirth_max = form.cleaned_data['rebirth_max']
            is_unlock = form.cleaned_data['is_unlock']
            image = form.cleaned_data['image']
            is_add_attack = form.cleaned_data['is_add_attack']
            is_for_init = form.cleaned_data['is_for_init']
            level_max = Card.get_level_max(rarity, 0);
            try:
                edit_card = False
                if (rarity != general.rarity) or (name != general.name):
                    edit_card = True
                general.name = name
                general.rarity = rarity
                general.level = level
                general.level_max = level_max
                general.group_id = group_id
                general.description = description
                general.attack = attack
                general.defence = defence
                general.rebirth_max = rebirth_max
                general.is_unlock = is_unlock
                general.is_for_init = is_for_init
                if image:
                    general.image = image
                general.is_add_attack = is_add_attack
                general.save()
                if edit_card:
                    _edit_card(general,"General")
            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:'general_edit'}).close();</script>")