当前位置: 首页>>代码示例>>Python>>正文


Python Book.buyout_price方法代码示例

本文整理汇总了Python中models.Book.buyout_price方法的典型用法代码示例。如果您正苦于以下问题:Python Book.buyout_price方法的具体用法?Python Book.buyout_price怎么用?Python Book.buyout_price使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在models.Book的用法示例。


在下文中一共展示了Book.buyout_price方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: sell

# 需要导入模块: from models import Book [as 别名]
# 或者: from models.Book import buyout_price [as 别名]
def sell():
    ''' 
    This function insert a book which the user sold to the database. Also, Checks if the user 
    has enough creadits to pay to the system for this sale.
    '''
    form = sellForm()
    if (request.method == 'POST') and form.validate_on_submit(): 
        #DETERMINE IF USER HAVE ENOUGH CREDIT TO SELL THE BOOK
        #GET USER ID
        username = request.form['username']
        user = User.query.filter_by(username = str(username)).first()
        userid = user.id
        #GET USER CREDITS
        user_credits = user.get_credit()
        #GET USER COMPLAINTS
        num_of_complaints = db.session.query(User_Complaints).filter_by(complained_id = userid).count()
        #CALCULATE CREDIT AFTER SALE
        temp_credit = user.credits  - ((int(request.form['saleDuration'])) * 5) - ((int(request.form['saleDuration'])) * num_of_complaints)
        #UPDATE USER CREDITS
        if (temp_credit < 0):
            return render_template('no_credit.html')
        user.credits = temp_credit
        file = form.data.get('bookImage')
        tempBool = 0
        b = Book()
        filename = ''.join(random.choice(string.ascii_letters+string.digits) for x in range(20))
        
        if (str(request.files['bookImage']) == "<FileStorage: u'' ('application/octet-stream')>"):    
            print "NO IMAGE"
            b.image_name = "noImage.jpg"
        else:
            #file = form.data.get('bookImage')
            file = request.files['bookImage']
            file.filename = filename+".jpg"
            if file and allowed_file(file.filename):
                #UPLOAD FILE
                filename = secure_filename(file.filename)
                file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
                b.image_name = filename
            
        #PUSH DATA TO DB
        b.title = request.form['title']
        b.author = request.form['author']
        b.isbn = request.form['isbn']
        b.price = float(request.form['price'])
        b.saleDuration = int(request.form['saleDuration'])
        b.publisher = request.form['publisher']
        b.numOfPages = int(request.form['numOfPages'])
        b.lang = request.form['lang']
        b.condition = request.form['condition']
        b.genre = request.form['genre']
        b.bookType = request.form['bookType']
        b.edition = int(request.form['edition'])
        b.information = request.form['information']
        #tempBool=0
        tempBool = False

        if (form.data.get('buyable') == True):
            #tempBool = 1;
            tempBool = True
        else:
            #tempBool = 0;
            tempBool = False
        b.buyable = tempBool
        if (tempBool == True):
        #if (tempBool == 1):
            b.buyout_price = float(request.form['buynowPrice'])
        # changing current_bid to price
        #b.current_bid=float(0)
        b.current_bid = b.price
        b.biddable= 1
        b.starting_bid=float(request.form['price'])
        b.owner_id=int(userid)
        db.session.add(b)
        db.session.commit()

        return render_template('success.html')

    return render_template('sell.html', form=form)
开发者ID:imclab,项目名称:BookBay,代码行数:81,代码来源:views.py


注:本文中的models.Book.buyout_price方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。