Ejemplo n.º 1
0
def good_add(request, template="admin/mall/good/add.tpl"):
    if request.method == "GET":
        return render_response(template)
    elif request.method == "POST":
        form = GoodForm(request.POST)
        if form.is_valid():
            name = form.cleaned_data["name"]
            type_id = form.cleaned_data["type_id"]
            vm = form.cleaned_data["vm"]
            rm = form.cleaned_data["rm"]
            discount = form.cleaned_data["discount"]
            description = form.cleaned_data["description"]
            image = form.cleaned_data["image"]
            is_new = form.cleaned_data["is_new"]
            is_hot = form.cleaned_data["is_hot"]
            is_unlock = form.cleaned_data["is_unlock"]
            try:
                good = Good.objects.create(
                    name=name,
                    type_id=type_id,
                    vm=vm,
                    rm=rm,
                    description=description,
                    discount=discount,
                    image=image,
                    is_new=is_new,
                    is_hot=is_hot,
                    is_unlock=is_unlock,
                )
                good.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:'good_add'}).close();</script>"
                )
Ejemplo n.º 2
0
def good_edit(request, good_id=0, template="admin/mall/good/edit.tpl"):
    good = Good.get_by_id(good_id)
    if request.method == "GET":
        return render_response(template, good=good)
    elif request.method == "POST":
        form = GoodForm(request.POST)
        if form.is_valid():
            name = form.cleaned_data["name"]
            type_id = form.cleaned_data["type_id"]
            vm = form.cleaned_data["vm"]
            rm = form.cleaned_data["rm"]
            discount = form.cleaned_data["discount"]
            description = form.cleaned_data["description"]
            image = form.cleaned_data["image"]
            is_new = form.cleaned_data["is_new"]
            is_hot = form.cleaned_data["is_hot"]
            is_unlock = form.cleaned_data["is_unlock"]
            try:
                good.name = name
                good.type_id = type_id
                good.vm = vm
                good.rm = rm
                good.discount = discount
                good.description = description
                good.image = image
                good.is_new = is_new
                good.is_hot = is_hot
                good.is_unlock = is_unlock
                good.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:'good_edit'}).close();</script>"
                )