def deal(): if "auth_field" in session: form = BidForm(user_id=session['_id']) if form.validate_on_submit(): deal_id = request.args['deal_id'] acc_id = request.args['acc_id'] number = request.form['number'] symbol = request.form['symbol'] return redirect( url_for('request_bid', deal_id=deal_id, acc_id=acc_id, number=number, symbol=symbol)) else: if 'id' in request.args: _id = request.args['id'] session['deal_id'] = _id dbcursor.execute("SELECT * FROM deals WHERE _id = %s", (_id, )) dbres = dbcursor.fetchone() return render_template("deal.room.html", dbres=dbres, form=form, acc_id=session["_id"]) else: dbcursor.execute("SELECT * FROM deals WHERE _id = %s", (session['deal_id'], )) dbres = dbcursor.fetchone() return render_template("deal.room.html", dbres=dbres, form=form, acc_id=session["_id"])
def render_home_page(): if current_user.is_authenticated: outstanding_ride_id = get_outstanding_payment_ride_id( current_user.username) if outstanding_ride_id: return redirect("/payment/{}".format(int(outstanding_ride_id[0]))) ad_list = get_filtered_ads(keywords=[], username=current_user.username) bid_list_query = "select a.time_posted::timestamp(0) as date_posted, a.departure_time::timestamp(0) as departure_time, " \ "a.driver_id, a.from_place, a.to_place, b.no_passengers, b.price as bid_price, b.status " \ "from advertisement a JOIN bids b ON a.driver_id = b.driver_id and a.time_posted = b.time_posted " \ "where " \ "b.passenger_id= '{}'".format(current_user.username) bid_list = db.session.execute(bid_list_query).fetchall() # Bid form handling form = BidForm() form.no_passengers.errors = '' form.price.errors = '' if request.method == "POST" and 'searchButton' in request.form: search_keywords = request.form['search'].split() ad_list = get_filtered_ads(search_keywords, current_user.username) elif form.is_submitted(): price = form.price.data no_passengers = form.no_passengers.data time_posted = form.hidden_dateposted.data driver_id = form.hidden_did.data min_price_query = "SELECT price FROM Advertisement WHERE time_posted = '{}' and driver_id = '{}'".format( time_posted, driver_id) min_price = db.session.execute(min_price_query).fetchone()[0] if form.validate_on_submit(): # disallow bidding to own-self's advertisement if int(no_passengers) > int(form.hidden_maxPax.data): form.no_passengers.errors.append( 'Max number of passengers allowed should be {}.'. format(form.hidden_maxPax.data)) elif int(price) < min_price: form.price.errors.append( 'Bidding price should be higher than the minimum price of {}.' .format(min_price)) else: error_message = makeBid(current_user.username, time_posted, driver_id, price, no_passengers) if error_message: form.price.errors.append(error_message) return redirect("/") return render_template("home.html", form=form, current_user=current_user, ad_list=ad_list, bid_list=bid_list) else: return redirect("/login")
def ajax(): form = BidForm() if form.validate_on_submit(): # utils.send_mail() return send_json_response( {'message': 'Ваша заявка успешно отправлена'}, 200) utils.write_log('eee') return send_json_response(form.errors, 400)
def ajax(): form = BidForm() if form.validate_on_submit(): send_email(name=form.name.data, phone=form.phone.data, message=form.message.data) return send_json_response( {'message': 'Ваша заявка успешно отправлена'}, 200) return send_json_response(form.errors, 400)
def browse_book(book_id): """test template to show one book so you can bid or buy pass in book.id as parameter to load book. """ form = BidForm() form2 = PostForm() try: user = User.query.filter_by(id = session['user_id']).first() is_guest = False except KeyError: print "is user anonymous? %s" % g.user.is_anonymous() # it errors here so user is guest. create a guest user to post with. is_guest = True guest = User.query.filter_by(username='******', email = '*****@*****.**').first() if not guest: guest = User( username = '******', first_name = 'GUEST', last_name = 'GUEST', email = '*****@*****.**', password = '******' ) db.session.add(guest) db.session.commit() else: session['user_id'] = guest.id book = Book.query.filter_by(id = book_id).first() if book is None: # temporary return 'book does not exist' else: #GET SELLER NAME AND RATING FOR LINK IN THE BOOK PAGE seller_id = book.get_seller() seller = User.query.filter_by(id = seller_id).first() seller_username = seller.get_username() try: seller_rating = seller.get_avg_rating() except ZeroDivisionError: seller_rating = 0; #COLLECTING DATA ABOUT THE USER if (is_guest == False): #CHECK IF USER HAVE PREFRENCE pref = Rec_Book.query.filter_by(user_id = user.id).first() if pref == None: #ENTER PREFRENCE TO REC_BOOK TABLE rb = Rec_Book() rb.user_id = user.id rb.genre = book.genre db.session.add(rb) db.session.commit() else: rb = Rec_Book.query.filter_by(user_id = user.id).first() rb.genre = book.genre db.session.commit() comments = Book_Comments.query.filter_by(book=book).order_by(desc(Book_Comments.timestamp)).all() if request.method == 'POST' and form.validate_on_submit() and form.bid_amount.data and is_guest == False and form.submit_bid: bid_amount = request.form['bid_amount'] book.create_bid(session['user_id'], bid_amount) # check if the user has enough credits u = User.query.filter_by(id = session['user_id']).first() if not(u.has_enough_credits(book.current_bid)): msg = 'You have %s credits. Current bid on book is %s.' % (u.return_credits(), book.current_bid) flash(msg) return render_template('browse_book.html', book=book, form=form, book_id=book_id, form2=form2, comments=comments, seller_name = seller_username, seller_rating = seller_rating, seller_id = seller_id) return render_template('browse_book.html', book=book, form=form, book_id=book_id, form2=form2, comments=comments, seller_name = seller_username, seller_rating = seller_rating, seller_id = seller_id) if request.method == 'POST' and form.submit_buy_now.data and is_guest == False: u = User.query.filter_by(id = session['user_id']).all() b = Book.query.filter_by(id = book_id).all() # check if user has enough credits to purchase book. # if True. continue transaction, if false, redirect. if user.has_enough_credits(book.get_buyout_price()): book.create_buy_now_transcation(user) flash ('you bought it, please provide your feedback') return render_template('rate_transaction.html',user = u, book = b) else: return redirect(url_for('not_enough_credits')) if request.method == 'POST' and form2.validate_on_submit() and form2.post.data: # have no idea why the other one doesnt work text = form2.post.data book.create_comment(session['user_id'], text) return render_template('browse_book.html', book=book, form=form, book_id=book_id, form2=form2, comments=comments, seller_name = seller_username, seller_rating = seller_rating, seller_id = seller_id) if is_guest is True: # delete session created by guest user del session['user_id'] comments = Book_Comments.query.filter_by(book=book).order_by(desc(Book_Comments.timestamp)).all() return render_template('browse_book.html', book=book, form=form, book_id=book_id, form2=form2, comments=comments, seller_name = seller_username, seller_rating = seller_rating, seller_id = seller_id)