Ejemplo n.º 1
0
    def __parse(self):
        '''
        :return: 一个字典组成的列表
        '''
        for gift_isbn in self.__my_gift_list:
            # 此处又要做一个viewmodel的适配,还是写在book里面比较好
            yushu = YuShuBook()
            # 根据礼物去查询书籍信息,返回到首页
            result = yushu.return_isbn(gift_isbn)
            newsresult = {}
            newsresult['author'] = result['author'][0]
            newsresult['isbn'] = result['isbn']
            newsresult['image'] = result['image']
            newsresult['title'] = result['title']
            newsresult['summary'] = result['summary']
            newsresult['publisher'] = result['publisher']
            newsresult['price'] = result['price']
            this_gift = Gift.query.filter_by(isbn=gift_isbn).first()

            if len(self.__my_wishes_count) != 0:
                for wish in self.__my_wishes_count:
                    if gift_isbn == wish['isbn']:
                        r = {
                            'id': this_gift.id,
                            'book': newsresult,
                            'wishes_count': wish['count']
                        }
                        self.mygifts.append(r)
            else:
                r = {'id': this_gift.id, 'book': newsresult, 'wishes_count': 0}
                self.mygifts.append(r)
        return self.mygifts
Ejemplo n.º 2
0
def satisfy_wish(wid):
    """
    向他人赠送书籍
    :param wid:wish的id号
    :return: 返回wish页面
    """
    # 两种查询方法之一:使用fliter_by需要查询两次,但是次数需要用到很多的数据,所以用第一种
    wish = Wish.query.filter_by(id=wid).first()
    wisher = User.query.filter_by(id=wish.uid).first()
    gift = Gift.query.filter_by(isbn=wish.isbn, uid=current_user.id).first()
    gifter = User.query.filter_by(id=gift.uid).first()
    yushu = YuShuBook()
    book = yushu.return_isbn(wish.isbn)
    # 使用fliter只要一次查询即可,fliter使用于跨表的查询
    # testuser=User.query.filter(Wish.id==wid).first()
    send_email(
        wisher.email,
        '有人想把书籍赠送给您',
        'email/satisify_wish.html',
        wisher=wisher,
        gift=gift,
        gifter=gifter,
        book=book
    )
    flash('已经有一封邮件发送到对方的邮箱')
    return redirect(url_for('web.book_detail', isbn=wish.isbn))
Ejemplo n.º 3
0
 def __parse(self):
     '''
     定义数据的转化
     :return: [{'id':xxx,'books':xxx,'count':xxx}]
     '''
     for wish_isbn in self.__wish_list:
         yushu = YuShuBook()
         # 根据礼物去查询书籍信息,返回到首页
         result = yushu.return_isbn(wish_isbn)
         newsresult = {}
         newsresult['author'] = result['author'][0]
         newsresult['isbn'] = result['isbn']
         newsresult['image'] = result['image']
         newsresult['title'] = result['title']
         newsresult['summary'] = result['summary']
         newsresult['publisher'] = result['publisher']
         newsresult['price'] = result['price']
         this_wish = Wish.query.filter_by(isbn=wish_isbn).first()
         if len(self.__gifts_count_of_wishes) != 0:
             for gift in self.__gifts_count_of_wishes:
                 if wish_isbn == gift['isbn']:
                     r = {
                         'id': this_wish.id,
                         'book': newsresult,
                         'wishes_count': gift['count']
                     }
                     self.my_wishes.append(r)
         else:
             r = {'id': this_wish.id, 'book': newsresult, 'wishes_count': 0}
             self.my_wishes.append(r)
     return self.my_wishes
Ejemplo n.º 4
0
def book_detail(isbn):

    # 表征数据的信息
    has_in_gifts = False
    has_in_wishes = False

    yushu = YuShuBook()
    result = yushu.return_isbn(isbn)

    # 20190305 在页面中显示索要者和赠送者的名单
    trade_gifts = Gift.query.filter_by(isbn=isbn, launched=False).all()
    trade_wishes = Wish.query.filter_by(isbn=isbn, launched=False).all()

    # 如果当前用户登陆了
    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_wishes_model = Tradeinfo(trade_wishes)
    trade_gifts_model = Tradeinfo(trade_gifts)

    return render_template(
        'book_detail.html',
        book=result,
        wishes=trade_wishes_model,
        gifts=trade_gifts_model,
        has_in_wishes=has_in_wishes,
        has_in_gifts=has_in_gifts
    )
Ejemplo n.º 5
0
def index():
    recent_gifts = Gift.recent()
    books = []
    bookmodel = BookViewModel()
    yushu = YuShuBook()
    # 根据礼物去查询书籍信息,返回到首页
    for gift in recent_gifts:
        result = yushu.return_isbn(gift.isbn)
        newsresult = {}
        newsresult['author'] = result['author'][0]
        newsresult['isbn'] = result['isbn']
        newsresult['image'] = result['image']
        newsresult['title'] = result['title']
        newsresult['summary'] = result['summary']
        books.append(newsresult)
    return render_template('index.html', recent=books)
Ejemplo n.º 6
0
def search():
    """接下去对q需要进行验证处理"""
    testform = SearchForms(request.args)
    newresult = ''
    if testform.validate():
        q = testform.q.data.strip()
        page = testform.page.data
        the_keyword = is_isbn_or_key(q)
        # 返回isbn的查询结果
        if the_keyword == 'isbn':
            yushu = YuShuBook()
            result = yushu.return_isbn(q)
            bookmodel = BookViewModel()
            newresult = bookmodel.get_isbn_book(result, q)
        # 返回key的查询结果
        if the_keyword == 'key':
            yushu = YuShuBook()
            result = yushu.return_key(q, page)
            bookmodel = BookViewModel()
            newresult = bookmodel.get_key_books(result, q)
    else:
        flash('您所输入的关键字存在错误!')
    return render_template('search_result.html', books=newresult)
Ejemplo n.º 7
0
 def book(cls, isbn):
     """返回isbn查询出来的书籍结果"""
     yushu = YuShuBook()
     result = yushu.return_isbn(isbn)
     return result