Ejemplo n.º 1
0
def book_update(book_id):
    db = DBOpera()
    if request.method == 'GET':
        book = db.get_bookAttach(book_id)
        class_list = db.get_classList()
        return render_template('manage_updatebook.html',
                               book=book,
                               class_list=class_list)
    if request.method == 'POST':
        book_name = request.form['book_name']
        book_author = request.form['book_author']
        book_price = request.form['book_price']
        book_class = request.form['book_class']
        book_message = request.form['book_message']
        file = request.files['book_image']
        book_num = request.form['book_num']
        db.update_book(book_id, book_name, book_author, book_class,
                       book_message, book_num, book_price)
        if file and allowed_file(file.filename):
            try:
                if not os.path.exists(os.path.join(UPLOAD_FOLDER,
                                                   str(book_id))):
                    os.mkdir(os.path.join(UPLOAD_FOLDER, str(book_id)))
                buddha = str(time.time())
                filename = buddha + '.' + file.filename.rsplit('.', 1)[1]
                book_image = os.path.join(UPLOAD_FOLDER, str(book_id),
                                          filename)
                fp = open(book_image, 'w')
                file.save(book_image)
                fp.close()
                db.add_bookImag(book_id, filename)
            except BaseException, e:
                print e
        return redirect(url_for('book_list'))
Ejemplo n.º 2
0
def book_detail(book_id):
    '''
    图书详情
    '''
    if request.method == 'GET':
        db = DBOpera()
        book = db.get_bookAttach(book_id)
        #########################图书信息字典###################################
        abook = {}
        abook['id'] = str(book.book_id)
        abook['name'] = book.book_name
        abook['author'] = book.book_author
        abook['message'] = book.book_message
        abook['price'] = book.book_price
        if book.book_image:
            abook['image'] = 'files/' + abook['id'] + '/' + book.book_image
        else:
            abook['image'] = ''
        ########################################################################
        evaluates = db.get_evaluate(book_id)
        evaluate_list = []
        if evaluates:
            for evaluate in evaluates:
                evaluate_dict = {}
                evaluate_dict['user_name'] = evaluate.evaluate_user_id
                evaluate_dict['datatime'] = evaluate.evaluate_time
                evaluate_dict['message'] = evaluate.evaluate_describe
                score = int(evaluate.evaluate_score)
                list0 = []
                list1 = []
                for i in range(score):
                    list0.append(i)
                for i in range(10 - score):
                    list1.append(i)
                evaluate_dict['score'] = list0
                evaluate_dict['no_score'] = list1
                evaluate_list.append(evaluate_dict)
        #print evaluate_list
        return render_template('user_product_page.html',
                               book=abook,
                               evaluates=evaluate_list)