Exemplo n.º 1
0
def book_detail(isbn):
    has_gifts = False
    has_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_gifts = True
        elif Wish.query.filter_by(uid=current_user.id,
                                  isbn=isbn,
                                  launched=False).first():
            has_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_gifts_model = TradeInfo(trade_gifts)
    trade_wishes_model = TradeInfo(trade_wishes)
    return render_template('book_detail.html',
                           book=book,
                           wishes=trade_wishes_model,
                           gifts=trade_gifts_model,
                           has_gifts=has_gifts,
                           has_wishes=has_wishes)
Exemplo n.º 2
0
def send_drift(gid):
    current_gift = Gift.query.get_or_404(gid)

    if current_gift.is_yourself_gift(current_user.id):
        flash("这本书是你自己的,不能向自己索要书籍哦~")
        return redirect(url_for("web.book_detail", isbn=current_gift.isbn))

    can = current_user.can_send_drift()
    if not can:
        return render_template("not_enough_beans.html",
                               beans=current_user.beans)

    form = DriftForm(request.form)
    if request.method == "POST" and form.validate():
        save_drift(form, current_gift)
        # 发送邮件提醒
        send_email(current_gift.user.email,
                   "有人向你请求一本书",
                   "email/get_gift.html",
                   wisher=current_user,
                   gift=current_gift)
        return redirect(url_for("web.pending"))

    gifter = current_gift.user.summary
    yushu_book = YuShuBook()
    yushu_book.search_by_isbn(current_gift.isbn)
    book = BookViewModel(yushu_book.first)
    return render_template("drift.html",
                           gifter=gifter,
                           book=book,
                           user_beans=current_user.beans,
                           form=form)
Exemplo n.º 3
0
 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
Exemplo n.º 4
0
 def __matching(self, trade):
     count = 0
     for trade_book in self.__book_trades_count_list:
         if trade.isbn == trade_book["isbn"]:
             count = trade_book["count"]
     my_trade = {
         "id": trade.id,
         "book": BookViewModel(trade.book),
         "trades_count": count
     }
     return my_trade
Exemplo n.º 5
0
 def __matching(self, gift):
     count = 0
     for wish_book in self.__book_wishes_count_list:
         if gift.isbn == wish_book["isbn"]:
             count = wish_book["count"]
     my_gift = {
         "id": gift.id,
         "book": BookViewModel(gift.book),
         "wishes_count": count
     }
     # my_gift = MyGift(gift.id, BookViewModel(gift.book), count)
     return my_gift
Exemplo n.º 6
0
def save_drift(drift_form, current_gift):
    with db.auto_commit():
        book = BookViewModel(current_gift.book)
        drift = Drift()
        drift_form.populate_obj(drift)
        drift.gift_id = current_gift.id
        drift.requester_id = current_user.id
        drift.requester_nickname = current_user.nickname
        drift.gifter_nickname = current_gift.user.nickname
        drift.gifter_id = current_gift.user.id
        drift.book_title = book.title
        drift.book_author = book.authors
        drift.book_img = book.image
        drift.isbn = book.isbn
        current_user.beans -= 1
        db.session.add(drift)
Exemplo n.º 7
0
def index():
    rencent_gifts = Gift.recent()
    books = [BookViewModel(gift.book) for gift in rencent_gifts]
    return render_template("index.html", recent=books)