Exemple #1
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)
Exemple #2
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_wishes_counts(isbn_list)
    view_model = MyGifts(gifts_of_mine, wish_count_list)
    return render_template('my_gifts.html', gifts=view_model.gifts)
Exemple #3
0
def my_gifts():
    uid = current_user.id
    gifts_of_mine = Gift.get_user_gifts(uid)
    gift_isbns = [gift.isbn for gift in gifts_of_mine]
    count_list = Gift.get_wish_count(gift_isbns)
    view_model = MyGifts(gifts_of_mine, count_list).gifts
    return render_template('my_gifts.html', gifts=view_model)
Exemple #4
0
def my_gifts():
    uid = current_user.id
    gifts = Gift.query.filter_by(uid=uid, launched=False).order_by(
        desc(Gift.create_time)).all()
    wishes_count = GiftService.get_wish_counts(gifts)
    view_model = MyGifts(gifts, wishes_count).package()
    return render_template('my_gifts.html', gifts=view_model)
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)
Exemple #6
0
def my_wish():
    uid = current_user.id
    wishes_of_mine = Wish.get_user_wishes(uid)
    # 获取wish的ISBN列表
    isbn_list = [wish.isbn for wish in wishes_of_mine]
    # 计算想送这本书的人数,返回人数 和 ISBN 的集合
    gift_count_list = Wish.get_gifts_counts(isbn_list)
    #gift 和 wish 的模板结构一样,复用gift的模板
    view_model = MyGifts(wishes_of_mine, gift_count_list)
    return render_template('my_wishes.html', wishes=view_model.gifts)
Exemple #7
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)
Exemple #8
0
def my_gifts():
    """
    http://localhost:8088/my/gifts
    """
    uid = current_user.id
    gifts_of_mine = Gift.get_user_gifts(uid)
    # 列表推导式获取礼物的isbn列表
    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)
    return render_template('my_gifts.html', gifts=view_model.gifts)
Exemple #9
0
def my_gifts():
    '''
    赠送清单: 将赠送清单gift要保存的信息保存
            1 用户id
            2 礼物数据(赠送的书籍列表)
            3 心愿数据(想要获取人数)
    :return:
    '''
    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_count(isbn_list)
    view_model = MyGifts(gifts_of_mine, wish_count_list)
    return render_template('my_gifts.html', gifts=view_model.gifts)
Exemple #10
0
def my_gifts():
    '''
    思路1 循环遍历我的礼物,根据每个礼物的isbn去Wish表中查这个书籍的相关心愿并计算数量
    思路2 取出每个礼物中的isbn编号 组成一个列表
    使用in查询去Wish表中查询在isbn列表中的心愿并计算数量

    这里使用思路2
    '''
    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)
    return render_template('my_gifts.html', gifts_of_mine=view_model.gifts)
Exemple #11
0
def my_gifts():
    """
    我的赠送清单
    :return:
    """

    cid = current_user.id

    my_gifts = Gift.get_user_gifts(uid=cid)

    isbn_list = [gift.isbn for gift in my_gifts]

    wish_count_list = Gift.get_wish_counts(isbn_list)

    wish_model = MyGifts(my_gifts, wish_count_list)
    return render_template('my_gifts.html', gifts=wish_model.gifts)
Exemple #12
0
def my_gifts():
    uid = current_user.id
    # 所有礼物
    gifts_of_mine = Gift.query.filter_by(uid=uid, launched=False).group_by(
        Gift.isbn).order_by(desc(Gift.create_time)).distinct().all()
    # (isbn: want_count, ...)
    isbn_list = [gift.isbn for gift in gifts_of_mine]

    wish_count_list = Gift.get_wish_counts(isbn_list=isbn_list)
    # view modes 合成数据
    # [{
    #     'wishes_count': count,
    #     'book': BookViewModel(gift.book),
    #     'id': gift.id
    # },
    # ...
    # ]
    view_models = MyGifts(gifts_of_mine, wish_count_list)
    from flask import render_template
    return render_template('my_gifts.html', gifts=view_models.my_gifts)
Exemple #13
0
def my_gifts():
    gifts_of_mine = Gift.get_user_gifts(current_user.id)  # gift model
    isbn_list = [gift.isbn for gift in gifts_of_mine]  # [str]
    wish_count_list = Gift.get_wish_count(isbn_list)  # [dict]
    my_gifts_view_model = MyGifts(gifts_of_mine, wish_count_list)
    return render_template('my_gifts.html', gifts=my_gifts_view_model.gifts)