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 bidInfo(demand_id): """ The '/bid/<demand_id>' route directs a user to the page with complete specifications for the demand. """ demand_info = Demand.get_info(demand_id) client_info = User.get_user_info(demand_info['client_username']) bids = Bid.get_bids_for_demand(demand_id) bids_info = [] bidders_info = {} if (len(bids) > 0): lowest_bid = Bid.get_info(bids[0])['bid_amount'] else: lowest_bid = 'None' for bid in bids: info = Bid.get_info(bid) bids_info.append(info) if info['developer_username'] not in bidders_info: bidders_info[info['developer_username']] = User.get_user_info( info['developer_username']) form = BidForm() if request.method == 'POST': if form.validate(): Bid(demand_id, session['username'], form.bid_amount.data) return redirect(url_for('bidInfo', demand_id=demand_id)) else: return redirect(url_for('bidInfo', demand_id=demand_id)) elif request.method == 'GET': return render_template("bidPage.html", demand_info=demand_info, client_info=client_info, bids_info=bids_info, bidders_info=bidders_info, lowest_bid=lowest_bid, form=form, demand_id=demand_id)
def test(): form = BidForm() return render_template('test.html', form=form)
def index(): form = BidForm() return render_template('index.html', form=form)