Beispiel #1
0
def detail(id):
    book = db.Details.find_one({"_id": id})
    review = db.Review.find_one({"_id": id})
    book_prices = sort_prices(review)
    recn = suggest_book(book, review)
    return render_template("details.html",
            book=book, prices=book_prices,review=review, recn=recn)
Beispiel #2
0
def search():

    # get isbn from search field
    isbn = request.args.get("isbn")

    # get the keywords
    keywords = request.args.get("keywords", "").strip()
    if not isbn and len(keywords) < 2:
            return render_template("Error.html")

    # compile to get 13 digit isbn
    pattern_13 = re.compile(r"\d{13}")
    if isbn:
        if pattern_13.search(isbn):
            isbn = pattern_13.search(isbn).group()
            if(is_isbn13(isbn)):
                isbn = isbn
            else:
                return render_template('Error.html')
        else:
            if(is_isbn10(isbn)):
                isbn = isbn
            else:
                return render_template('Error.html')
        size = len(isbn)
        if size == 10:
            detail = db.Details.find_one({'ISBN-10':isbn})
            isbn = detail.get('_id')
        else:
            detail = db.Details.find_one({'_id': isbn})
        review = db.Review.find_one({'_id': isbn})
        if detail:
            book_prices = sort_prices(review)
            return render_template("details.html",
                         book=detail, review=review, prices=book_prices)
        else:
            return render_template("Error.html")
    elif keywords:
        if len(keywords) == 0:
            return render_template("Error.html")
        else:

            books = db.Details.find({'keywords':
                            re.compile(keywords, re.IGNORECASE)}).limit(37)
            if (books.count() != 0):
                return render_template("results.html",
                                books=books)
            else:
                return render_template("Error.html")
    else:
        return render_template("Error.html")