Esempio n. 1
0
def my_gifts():
    user_id = current_user.id
    user_gifts = Gift.get_user_gifts(user_id)
    isbn_list = [i.isbn for i in user_gifts]
    wish_count_list = Gift.get_wish_counts(isbn_list)

    return 'my gifts'
Esempio n. 2
0
def save_to_gifts(isbn):
    """
    赠送 礼物, 书籍
    :param isbn:
    :return:

    # 数据库事务 sqlalchemy  事务操作


    回滚
    rollback



    """

    if current_user.can_save_tolist(isbn):

        with db.auto_commit():
            gift = Gift()
            gift.isbn = isbn
            gift.uid = current_user.id

            # xxxxerror
            current_user.beans += BEANS_UPLOAD_ONE_BOOK
            db.session.add(gift)
    else:

        flash("这本书已经添加到你的赠送清单里面了. Sorry,can't save isbn:{}".format(isbn))
        # return "sorry,can't save isbn:{}".format(isbn)

    return redirect(url_for('web.book_detail', isbn=isbn))
Esempio n. 3
0
def save_to_gifts(isbn):
    if current_user.can_save_to_list(isbn):  # 这里是判断是否是在用户的清单中
        # 如果存储出错,实行事务回滚
        #         try:
        #             gift = Gift()
        #             gift.isbn = isbn
        #             gift.uid = current_user.id  # 获取当前用户的ID,该用户存储在LoginManger中
        #             current_user.beans += current_app.config['BEANS_UPLOAD_ONE_BOOK'] # 增加鱼豆的数量
        #             db.session.add(gift)
        #             db.session.commit()
        #         except Exception as e:
        #             db.session.rollback()
        #             raise e

        with db.auto_commit():
            gift = Gift()
            gift.isbn = isbn
            gift.uid = current_user.id  # 获取当前用户的ID,该用户存储在LoginManger中
            current_user.beans += current_app.config[
                'BEANS_UPLOAD_ONE_BOOK']  # 增加鱼豆的数量
            db.session.add(gift)
    else:
        print('这本书已经添加到你要赠送的清单或已经存在于你的心愿清单,请不要重复添加!')
        flash('这本书已经添加到你要赠送的清单或已经存在于你的心愿清单,请不要重复添加!')
    # 赠送成功后跳转到原书本详情页面
    return redirect(url_for('web.book_detail', isbn=isbn))
Esempio n. 4
0
def my_gifts():
    uid = getattr(g, REQUEST_USER_ID)
    gifts_of_mine = Gift.get_user_gifts(uid)
    isbns = [gift.isbn for gift in gifts_of_mine]
    wish_counts = Gift.get_wish_counts(isbns)
    view = MyGifts(gifts_of_mine, wish_counts)
    return SuccessResponse(data=view.gifts)()
Esempio n. 5
0
def save_to_gifts(isbn):
    if current_user.can_save_to_list(isbn):

        with db.auto_commit():
            gift = Gift()
            gift.isbn = isbn
            gift.uid = current_user.id
            current_user.beans += current_app.config['BEANS_UPLOAD_ONE_BOOK']
            db.session.add(gift)
        """
        try:
            gift = Gift()
            gift.isbn = isbn
            gift.uid = current_user.id
            current_user.beans += current_app.config['BEANS_UPLOAD_ONE_BOOK']
            db.session.add(gift)
            db.session.commit()
        except Exception as e:
            db.session.rollback()
            raise e
        """

    else:
        flash('这本书已添加至你的赠送清单或存在于你的心愿清单,请不要重复添加')
    return redirect(url_for('web.book_detail', isbn=isbn))
Esempio n. 6
0
def my_gifts():
    uid = current_user.id
    gifts_of_mine = Gift.get_user_gifts(uid)  #根据当前用户id获取其对应的赠送清单
    isbn_list = [wish.isbn for wish in gifts_of_mine]  #获取赠送清单中全部书籍的isbn号
    wish_count_list = Gift.get_wish_counts(isbn_list)  #根据isbn号查询Wish表有哪些人想要这本书
    view_model = MyTrades(gifts_of_mine, wish_count_list)
    return render_template('my_wish.html', wishes=view_model.trades)
Esempio n. 7
0
def my_gifts():
    uid = current_user.id
    gifts_of_mime = Gift.get_user_gifts(uid)
    isbn_list = [gift.isbn for gift in gifts_of_mime]
    wish_count_list = Gift.get_wish_counts(isbn_list)
    view_model = MyGifts(gifts_of_mime, wish_count_list)
    return render_template('my_gifts.html', gifts=view_model.gifts)
Esempio n. 8
0
def save_to_gifts(isbn):
    '''
    check if isbn valid
    check if book exists
    :param isbn:
    :return:
    '''
    if current_user.can_save_to_list(isbn):
        # transaction
        # enable consistency
        # rollback
        # try:
        with db.auto_commit():
            # here the code is what do after yield
            gift = Gift()
            gift.isbn = isbn
            gift.uid = current_user.id
            current_user.beans += current_app.config['BEANS_UPLOAD_ONE_BOOK']
            db.session.add(gift)

            # db.session.commit()
        # except Exception as e:
        #     db.session.rollback()
        #     raise e
    else:
        flash('already added to your wish list or gift list!')
    return redirect(url_for('web.book_detail', isbn=isbn))
Esempio n. 9
0
def my_gifts():
    uid = current_user.id
    gifts_list = Gift.get_user_gifts(uid)
    gifts_isbn = [gift.isbn for gift in gifts_list]
    gifts_wishes_count = Gift.get_wishes_count(gifts_isbn)
    my_gifts_view_model = MyTrades(gifts_list, gifts_wishes_count)
    return render_template('my_gifts.html', gifts=my_gifts_view_model.trades)
Esempio n. 10
0
def my_gifts():
    uid = current_user.id
    gifts_of_mine = Gift.get_user_gifts(uid)
    isbn_list = [gift.isbn for gift in gifts_of_mine]
    wish_count_list = Gift.get_wish_counts(isbn_list)
    view_model = MyTrade(gifts_of_mine, wish_count_list)
    return render_template('my_gifts.html', gifts=view_model.trades)
Esempio n. 11
0
def my_gifts():
    uid = current_user.id
    gifts_of_mine = Gift.get_user_gift(uid)
    isbn_list = [gift.isbn for gift in gifts_of_mine]
    wish_count_list = Gift.get_wish_counts(isbn_list)
    view_model = MyTrades(gifts_of_mine, wish_count_list)
    return render_template("my_gifts.html", gifts=view_model.trades)
Esempio n. 12
0
def my_gifts():
    uid = current_user.id
    gifts_of_mine = Gift.get_user_gifts(uid)
    book_id_list = [gift.book_id for gift in gifts_of_mine]
    wish_count_list = Gift.get_wish_counts(book_id_list)
    view_model = MyGifts(gifts_of_mine, wish_count_list)
    return render_template('my_gifts.html', gifts=view_model.gifts)
Esempio n. 13
0
def save_to_gift(isbn):
    if current_user.can_save_to_list(isbn):
        '''
        # 事务
        try:
            gift = Gift()
            gift.isbn = isbn
            # User模型里实现的方法
            gift.uid = current_user.id
            # 加鱼豆
            current_user.beans += current_app.config['BEANS_UPLOAD_ONE_BOOK']
            db.session.add(gift)
            # 上面操作了两张表,SQLAlchemy天然支持事务
            db.session.commit()
        except Exception as e: # 如果不回滚,那么这次和后续的插入都会失败
            db.session.rollback()
            raise e
        '''
        with db.auto_commit():
            gift = Gift()
            gift.isbn = isbn
            # User模型里实现的方法
            gift.uid = current_user.id
            # 加鱼豆
            current_user.beans += current_app.config['BEANS_UPLOAD_ONE_BOOK']
            db.session.add(gift)
    else:
        flash('你当前有赠送这本书或你心愿清单里有这本书')

    return redirect(url_for('web.book_detail', isbn=isbn))
Esempio n. 14
0
def my_gifts():
    uid = current_user.id
    gifts_of_mine = Gift.get_user_gifts(uid)
    isbn_list = [gift.isbn for gift in gifts_of_mine]
    wish_count_list = Gift.get_wish_counts(isbn_list)
    view_model = MyGifts(gifts_of_mine, wish_count_list)  # 因为gifts和wishes的viewmodel是完全一样的 我们可以封装一个trade就行 如果这里要使用 改这两行代码
    return render_template('my_gifts.html', gifts=view_model.gifts)
Esempio n. 15
0
def my_gifts():
    uid = current_user.id
    gifts_of_mine = Gift.get_user_gifts(uid)
    isbn_list = [gift.isbn for gift in gifts_of_mine]
    wishes_count_list = Gift.get_wish_counts(isbn_list)

    my_gifts = MyTrades(gifts_of_mine, wishes_count_list)
    return render_template('my_gifts.html', gifts=my_gifts.trades)
Esempio n. 16
0
def my_gifts():
    uid = current_user.id
    gifts = Gift.get_user_gifts(uid)
    isbn_list = [gift.isbn for gift in gifts]
    wish_count_list = Gift.get_wish_counts(isbn_list)
    # Gift.get_wish_counts(isbn_list)
    view_model = MyTrades(gifts, wish_count_list)
    return render_template('my_gifts.html', gifts=view_model.trades)
Esempio n. 17
0
def my_gifts():
    uid = current_user.id
    gifts_of_mine = Gift.get_user_gifts(uid)
    # 根据查询的礼物列表将每个礼物的isbn查询出来组成列表
    gifts_isbn_list = [gift.isbn for gift in gifts_of_mine]
    wish_count_list = Gift.get_wish_counts(gifts_isbn_list)
    my_gifts_view_model = MyTrades(gifts_of_mine, wish_count_list)
    return render_template('my_gifts.html', gifts=my_gifts_view_model.trades)
Esempio n. 18
0
def my_gifts():
    gifts_of_mine = Gift.get_user_gifts(current_user.id)
    isbn_list = [gift.isbn for gift in gifts_of_mine]
    wishes_count_list = Gift.get_wish_counts(isbn_list)
    giftViewModel = MyGiftViewModels(gifts_of_mine, wishes_count_list)
    print("*************************")
    print(giftViewModel.gifts)
    return render_template("my_gifts.html", gifts=giftViewModel.gifts)
Esempio n. 19
0
def my_gifts():
    uid = current_user.id
    gifts_of_mine = Gift.get_user_gifts(uid)  # 用户的礼物清单
    # 需要查询想要书籍的人数
    isbn_list = [gift.isbn for gift in gifts_of_mine]
    wish_count_list = Gift.get_wish_counts(isbn_list)
    view_model = MyTrades(gifts_of_mine, wish_count_list)
    return render_template('my_gifts.html', gifts=view_model.trades)
Esempio n. 20
0
def my_gifts():
    uid = current_user.id
    gifts = Gift.query.filter_by(uid=uid, launched=False).order_by(
        desc(Gift.create_time)).all()
    gifts_of_mine = Gift.get_user_gifts(uid)
    isbn_list = [gift.isbn for gift in gifts]
    wish_count_list = Gift.get_wish_counts(isbn_list)
    view_model = MyGifts(gifts_of_mine, wish_count_list)
    return render_template('my_gifts.html', gifts=view_model.gifts)
Esempio n. 21
0
def my_gifts():
    uid = current_user.id
    from app.models.gift import Gift
    gifts_of_mine = Gift.get_user_gifts(uid)
    isbn_list = [gift.isbn for gift in gifts_of_mine]
    wish_count_list = Gift.get_wish_counts(isbn_list)
    # view_model = MyGifts(gifts_of_mine,wish_count_list)
    view_model = MyTrades(gifts_of_mine, wish_count_list)
    return render_template('my_gifts.html', gifts=view_model.trades)
Esempio n. 22
0
def save_to_gift(bid):
    # 事务
    with db.auto_commit():
        gift = Gift()
        gift.bid = bid
        gift.uid = current_user.id
        current_user.beans = 1
        db.session.add(gift)
    return 'ok'
Esempio n. 23
0
def my_gifts():
    uid = current_user.id
    gifts_of_mine = Gift.get_user_gifts(uid)
    #获取gift的ISBN列表
    isbn_list = [gift.isbn for gift in gifts_of_mine]
    #计算想要这本书的人数,返回人数 和 ISBN 的集合
    wish_count_list = Gift.get_wish_counts(isbn_list)
    #修改格式显示
    view_model = MyGifts(gifts_of_mine, wish_count_list)
    return render_template('my_gifts.html', gifts=view_model.gifts)
Esempio n. 24
0
def save_to_gifts(isbn):
    if current_user.can_save_to_list(isbn):
        with db.auto_commit():
            gift = Gift()
            gift.isbn = isbn
            gift.uid = current_user.id
            current_user.beans += current_app.config['BEANS_UPLOAD_ONE_BOOK']
            db.session.add(gift)
    else:
        flash('不要重复赠送书籍或添加愿望清单')
Esempio n. 25
0
def save_to_wish(isbn):
    if current_user.can_save_to_list(isbn):
        with db.auto_commit():
            gift = Gift()
            gift.isbn = isbn
            gift.uid = current_user.id
            db.session.add(gift)
    else:
        flash('这本书已添加至您的赠送清单或者心愿清单,请勿重复添加')
    return redirect(url_for('web.book_detail', isbn=isbn))
Esempio n. 26
0
def save_to_gifts(isbn):
    gift = Gift()
    gift.isbn = isbn
    gift.uid = current_user.id
    # current_user.beans += 0.5
    current_user.beans += current_app.config['BEANS_UPLOAD_ONE_BOOK']
    db.session.add(gift)
    db.session.commit()

    pass
Esempio n. 27
0
def save_to_gifts(isbn):
    if current_user.can_save_to_list(isbn):
        with db.auto_commit():
            gift = Gift()
            gift.isbn = isbn
            gift.uid = current_user.id
            current_user.beans += current_app.config['BEANS_UPLOAD_ONE_BOOK']
            db.session.add(gift)
    else:
        flash('这本书已经添加到你的赠送清单或已经存在与你的心愿清单,请不要重复添加')
Esempio n. 28
0
def save_to_gifts(isbn):
    if current_user.can_save_to_db(isbn):
        with db.auto_commit():
            gift = Gift()
            gift.isbn = isbn
            gift.uid = current_user.id
            current_user.beans += current_app.config['BEANS_UPLOAD_ONE_BOOK']
            db.session.add(gift)
    else:
        flash("这本书已经添加至你的赠送清单或者已经存在于你的心愿清单,请勿重复添加。")
    return redirect(url_for('web.book_detail', isbn=isbn))
Esempio n. 29
0
def save_to_gifts(isbn):
    if current_user.can_save_to_list(isbn):
        with db.auto_commit():
            gift = Gift()
            gift.isbn = isbn
            gift.id = current_user.id
            current_user.beans += current_user.config['BEANS_UPLOAD_ONE_BOOK']
            db.session.add(gift)
    else:
        flash('这本书已添加到赠送清单或心愿清单,请不要重复添加')
    return redirect(url_for('web.book_detail', isbn=isbn))
Esempio n. 30
0
def save_to_gifts(isbn):
    if current_user.can_save_to_list(isbn):
        with db.auto_commit():
            gift = Gift()
            gift.isbn = isbn
            gift.uid = current_user.id
            current_user.beans += current_app.config["BEANS_UPLOAD_BOOK"]
            db.session.add(gift)
    else:
        flash("这本书已添加至你的赠送清单或已存在于你的心愿清单")
    return redirect(url_for("web.book_detail", isbn=isbn))
Esempio n. 31
0
def get_recently_upload():
    start = request.args['start']
    pre_page_count = current_app.config['PRE_PAGE_COUNT']
    recently_upload = Gift.paged_query(start,
                                       pre_page_count,
                                       soft=True,
                                       launched=False)
    books = [r_u.book for r_u in recently_upload]
    total = Gift.get_total(soft=True, launched=False)
    result = {'books': books, 'total': total}
    return jsonify(result)
Esempio n. 32
0
def save_to_gifts(isbn):
    if current_user.can_save_to_list(isbn):
        with db.auto_commit():
            gift = Gift()
            gift.isbn = isbn
            gift.uid = current_user.id

            current_user.beans += current_app.config['BEANS_UPLOAD_ONE_BOOK']

            db.session.add(gift)
    else:
        flash("这本书以添加进您的赠送清单或已经存在于您的心愿清单,请不要重复添加")
    return redirect(url_for('web.book_detail', isbn=isbn))
Esempio n. 33
0
def save_to_gifts(isbn):
    if current_user.can_save_to_list(isbn):
        # 事务,保证user和gift的一致性,rollback
        # try:
        with db.auto_commit():
            gift = Gift()
            gift.isbn = isbn
            gift.uid = current_user.id
            #################################################
            current_user.beans += current_app.config['BEANS_UPLOAD_ONE_BOOK']
            db.session.add(gift)
            # db.session.commit()
        # except Exception as e:
        #     db.session.rollback()
        #     raise e
    else:
        flash('这本书已经添加至你的赠送清单或者一存在于你的心愿清单,请不要重复添加')
    return redirect('web.book_detail', isbn=isbn)
Esempio n. 34
0
def index():
    recent_gifts = Gift.recent()
    books = [BookViewModel(gift.book) for gift in recent_gifts]
    return render_template('index,html', recent=books)