How to use the tblib.model.session.add function in tblib

To help you get started, we’ve selected a few tblib examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github shiyanlou / louplus-python / taobei / tbuser / handlers / address.py View on Github external
def create_address():
    """添加地址
    """

    data = request.get_json()

    address = AddressSchema().load(data)
    session.add(address)
    session.commit()

    return json_response(address=AddressSchema().dump(address))
github shiyanlou / louplus-python / taobei / tbuser / handlers / wallet_transaction.py View on Github external
User.wallet_money: payer.wallet_money - wallet_transaction.amount
    })
    if count == 0:
        session.rollback()
        return json_response(ResponseCode.TRANSACTION_FAILURE)

    count = User.query.filter(
        and_(User.id == payee.id, User.wallet_money == payee.wallet_money)
    ).update({
        User.wallet_money: payee.wallet_money + wallet_transaction.amount
    })
    if count == 0:
        session.rollback()
        return json_response(ResponseCode.TRANSACTION_FAILURE)

    session.add(wallet_transaction)

    session.commit()

    return json_response(wallet_transaction=WalletTransactionSchema().dump(wallet_transaction))
github shiyanlou / louplus-python / taobei / tbbuy / handlers / cart_product.py View on Github external
CartProduct.user_id == cart_product.user_id).all()

    # 商品是否已在购物车
    existed = None
    for v in cart_products:
        if v.product_id == cart_product.product_id:
            existed = v
            break

    # 购物车商品数量不能超过限制
    if len(cart_products) >= current_app.config['CART_PRODUCT_LIMIT'] and existed is None:
        return json_response(ResponseCode.QUANTITY_EXCEEDS_LIMIT)

    # 商品已在购物车则更新数量,否则添加一条新纪录
    if existed is None:
        session.add(cart_product)
    else:
        existed.amount += cart_product.amount
    session.commit()

    return json_response(cart_product=CartProductSchema().dump(cart_product if existed is None else existed))
github shiyanlou / louplus-python / taobei / challenge-02 / tbmall / handlers / product.py View on Github external
def create_product():
    """创建商品
    """

    data = request.get_json()

    product = ProductSchema().load(data)
    session.add(product)
    session.commit()

    return json_response(product=ProductSchema().dump(product))
github shiyanlou / louplus-python / taobei / challenge-02 / tbmall / handlers / shop.py View on Github external
def create_shop():
    """创建店铺
    """

    data = request.get_json()

    shop = ShopSchema().load(data)
    session.add(shop)
    session.commit()

    return json_response(shop=ShopSchema().dump(shop))
github shiyanlou / louplus-python / taobei / tbmall / handlers / favorite_product.py View on Github external
def create_favorite_product():
    """收藏商品
    """

    data = request.get_json()

    favorite_product = FavoriteProductSchema().load(data)
    session.add(favorite_product)
    session.commit()

    return json_response(favorite_product=FavoriteProductSchema().dump(favorite_product))