Beispiel #1
0
def my_wishes():
    wish_list_models = current_user.wishes
    wish_list = [BookViewModel(wish.book) for wish in wish_list_models]
    total = len(wish_list)
    return render_template('wish-list.html',
                           wish_list=wish_list,
                           total=total)
Beispiel #2
0
def book_detail(isbn):
    yushu_book = YuShuBook()
    yushu_book.search_by_isbn(isbn)

    book = BookViewModel(yushu_book.first)

    has_in_gifts = False
    has_in_wishes = False
    if current_user.is_authenticated:
        # 如果未登录,current_user将是一个匿名用户对象
        if Gift.query.filter_by(uid=current_user.id, isbn=isbn,
                                launched=False).first():
            has_in_gifts = True
        if Wish.query.filter_by(uid=current_user.id, isbn=isbn,
                                launched=False).first():
            has_in_wishes = True

    # 显示关于本书的相关 gift 和 wish,并根据书处于当前用户 gift 列表 或者 wish 列表,进行显示
    # 默认显示所有想要赠送这本书的用户信息
    wishes = TradeInfo(Wish.query.filter_by(
        isbn=isbn,
        launched=False).all())  # 这里从 model 中拿到数据,然后到 viewmodel 中进行裁剪
    gifts = TradeInfo(Gift.query.filter_by(isbn=isbn, launched=False).all())

    return render_template('book_detail.html',
                           book=book,
                           has_in_gifts=has_in_gifts,
                           has_in_wishes=has_in_wishes,
                           wishes=wishes,
                           gifts=gifts)
def book_detail(isbn):
    has_in_gifts = False
    has_in_wishes = False

    yushu_book = YuShuBook()
    yushu_book.search_by_isbn(isbn)
    book = BookViewModel(yushu_book.first)

    if current_user.is_authenticated:
        if Gift.query.filter_by(uid=current_user.id, isbn=isbn,
                                launched=False).first():
            has_in_gifts = True
        if Wish.query.filter_by(uid=current_user.id, isbn=isbn,
                                launched=False).first():
            has_in_wishes = True

    trade_gifts = Gift.query.filter_by(isbn=isbn, launched=False).all()
    trade_wishes = Wish.query.filter_by(isbn=isbn, launched=False).all()

    trade_wishes_model = TradeInfo(trade_wishes)
    trade_gifts_model = TradeInfo(trade_gifts)

    return render_template('book_detail.html',
                           book=book,
                           wishes=trade_wishes_model,
                           gifts=trade_gifts_model,
                           has_in_wishes=has_in_wishes,
                           has_in_gifts=has_in_gifts)
Beispiel #4
0
 def _fill(self, uid):
     gifts = Gift.query.filter_by(uid=uid, launched=False).order_by(
         desc(Gift.create_time)).all()
     bookisbn_to_wants_map = Gift.get_wish_counts(gifts)
     return [{
         'wishes_count': bookisbn_to_wants_map[gift.isbn],
         'book': BookViewModel(gift.book),
         'id': gift.id
     } for gift in gifts]
Beispiel #5
0
def my_presents():
    present_list_models = current_user.presents
    present_list = [
        BookViewModel(present.book) for present in present_list_models
    ]
    total = len(present_list)
    return render_template('presents-list.html',
                           present_list=present_list,
                           total=total)
Beispiel #6
0
 def _fill(self, uid):
     wishes = Wish.query.filter_by(uid=uid, launched=False).order_by(
         desc(Wish.create_time)).all()
     bookisbn_to_gives_map = Wish.get_gift_counts(wishes)
     return [{
         'wishes_count': bookisbn_to_gives_map[wish.isbn],
         'book': BookViewModel(wish.book),
         'id': wish.id
     } for wish in wishes]
 def __matching(self, gift):
     count = 0
     for wish_count in self.__wish_count_list:
         if gift.isbn == wish_count['isbn']:
             count = wish_count['count']
     r = {
         'wishes_count': count,
         'book': BookViewModel(gift.book),
         'id': gift.id
     }
     return r
Beispiel #8
0
 def __matching(self, trade):
     count = 0
     for trade_count in self.__trades_count_list:
         if trade.isbn == trade_count['isbn']:
             count = trade_count['count']
     r = {
         'trades_count': count,
         'book': BookViewModel(trade.book),
         'id': trade.id
     }
     return r
Beispiel #9
0
def admin():
    if current_user.student_id != '1602140129':
        abort(404)
    users = User.query.all()
    trads = Trad.query.all()
    presents = Present.query.all()
    wishes = Wish.query.all()
    books = Book.query.all()
    if books:
        books = [BookViewModel(book) for book in books]
    if users:
        users = [user.intro for user in users]

    return render_template('admin.html',
                           users=users,
                           books=books,
                           trads=trads,
                           presents=presents,
                           wishes=wishes)
Beispiel #10
0
def book_detail(number):
    wishes_note = []
    presents_note = []
    search_book = SearchBook()
    search_book.search_by_number(number)
    # search_book.books属性下存放book模型的集合--list
    book = search_book.first
    wishes_list = book.wishes
    presents_list = book.presents
    if wishes_list:
        # 得到所有的wish用户的模型
        wishes_note = [wish.owner for wish in wishes_list]
    if presents_list:
        # 得到所有的present用户的模型
        presents_note = [present.owner for present in presents_list]

    book = BookViewModel(book)

    return render_template('book-detail.html', book=book,
                           wishes_note=wishes_note, presents_note=presents_note)
Beispiel #11
0
def save_dirft(dirft_form, current_gift):
    with db.auto_commit():
        drift = Drift()
        dirft_form.populate_obj(drift)

        drift.gift_id = current_gift.id
        drift.requester_id = current_user.id
        drift.requester_nickname = current_user.nickname
        drift.gifter_id = current_gift.user.id
        drift.gifter_nickname = current_gift.user.nickname

        book = BookViewModel(current_gift.book)

        drift.book_title = book.title
        drift.book_author = book.author
        drift.book_img = book.image
        drift.isbn - book.isbn

        current_user.beans -= 1

        db.session.add(drift)
Beispiel #12
0
def recent():
    page = request.args.get('page', 1, type=int)
    books_list = Book.recent_books(page)
    books = [BookViewModel(book) for book in books_list]
    return render_template('index.html', books=books)
Beispiel #13
0
 def recent():
     gift_list = Gift.query.filter_by(launched=False).order_by(
         desc(Gift.create_time)).limit(
             current_app.config['RECENT_BOOK_PER_PAGE']).all()
     books = [BookViewModel(gift.book) for gift in gift_list]
     return books
Beispiel #14
0
def index():
    recent_gifts = Gift.recent()
    books = [BookViewModel(gift.book) for gift in recent_gifts]
    return render_template('index.html', recent=books)