Beispiel #1
0
def remove_cart():
    id = request.args["id"]
    if id:
        ShoppingCart.remove_cart(id)
        return Success(msg="移除成功")
    else:
        return ParameterException(msg="请传入商品id")
Beispiel #2
0
def address_delete():
    id = request.args["id"]
    if id:
        Address.delete_address(id=id)
        return Success(msg="删除成功")
    else:
        return ParameterException(msg="请传入地址id")
Beispiel #3
0
def append_cart():
    data = eval(str(request.data, encoding='utf-8'))
    form = Append_Cart(ImmutableMultiDict(data))
    if form.validate():
        ShoppingCart.append_cart(form)
        return Success(msg="加入购物成功")
    else:
        return ParameterException(msg=form.errors)
Beispiel #4
0
def amend():
    data = eval(str(request.data, encoding='utf-8'))
    form = AddressAmend(ImmutableMultiDict(data))

    if form.validate():
        Address.amend_default_address(form)
        return Success(msg="更改地址成功")
    else:
        return ParameterException(msg=form.errors)
Beispiel #5
0
 def clear_cart(cls):
     cart = ShoppingCart.query.filter_by(delete_time=None).all()
     if cart:
         date = datetime.now()
         for item in cart:
             item.update(delete_time=date, commit=True)
         return Success(msg="清空成功")
     else:
         return NotFound(msg="空空如已")
Beispiel #6
0
def add_comm():
    """
    添加商品信息
    :return:
    """
    data = eval(str(request.data, encoding='utf-8'))
    form = CommForm(ImmutableMultiDict(data))
    if form.validate():
        Commodity.insert_comm(data)     # 添加商品到数据库
        return Success(msg="添加商品成功")
    else:
        return Failed(msg=form.errors)
Beispiel #7
0
def put_comm():
    """
    更新商品信息
    :return:
    """
    data = eval(str(request.data, encoding='utf-8'))
    form = PutCommForm(ImmutableMultiDict(data))
    if form.validate():
        if Commodity.update_comm(data):
            return Success(msg="更新商品成功")

    else:
        return Failed(msg=form.errors)
Beispiel #8
0
def del_comm():
    """
    删除商品信息
    :return:
    """
    id = request.args["id"]
    if id:
        comm = Commodity.del_comm(id)
        if comm:
            return Success(msg="删除商品成功")
        else:
            return Failed(msg="此商品不存在")
    else:
        return Failed(msg="请传入商品id")