Exemplo n.º 1
0
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"])
Exemplo n.º 2
0
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")
Exemplo n.º 3
0
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)
Exemplo n.º 4
0
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)
Exemplo n.º 5
0
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 new_bid():
    if request.method == 'POST':
        # request user for creating bid
        user = User.query.filter_by(username=current_user.username).first()
        form = BidForm(request.form)

        if form.validate():
            form.user = user
            # create bid object
            bid = Bid(user=user, **form.data)

            # updating user vacation days
            User.query.filter_by(
                id=user.id
            ).update({'vacation_days': user.vacation_days - form.vac_days.data})

            db.session.add(bid)
            db.session.commit()

            # check commit to db
            vac_date = Bid.query.filter_by(
                vac_date=bid.vac_date
            ).filter_by(
                user_id=user.id
            ).first().vac_date

            if vac_date:
                flash('Vacation "{}" created!'.format(vac_date))
            else:
                flash('Vacation did not created!')

            return redirect(url_for('home.personal_area'))
        else:
            return render_template('new_bid.html', form=form)

    form = BidForm()

    return render_template('new_bid.html', form=form)
Exemplo n.º 7
0
def view_auction_event(request, id):
    try:
        auction_event = AuctionEvent.objects.get(pk=int(id))
    except AuctionEvent.DoesNotExist:
        raise Http404

    Seller = auction_event.Seller
    bidder = User.objects.get(username = request.user)

    if request.method == 'POST':
        if Seller != bidder:
            form = BidForm(data= request.POST,auction_event = auction_event, bidder= request.user)
            if form.is_valid():
                bid = form.save(commit=False)
                return HttpResponseRedirect(request.get_full_path())
        else:
            return render_to_response("view_auction.html", locals(),
            context_instance=RequestContext(request))
    else:
        form = BidForm(initial={'amount': auction_event.get_current_price() + Decimal('0.01')})

        return render_to_response('view_auction.html',{'form': form,'auction_event': auction_event
        }, context_instance=RequestContext(request))
Exemplo n.º 8
0
def test():
    form = BidForm()
    return render_template('test.html', form=form)
Exemplo n.º 9
0
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)
Exemplo n.º 10
0
def index():
    form = BidForm()
    return render_template('index.html', form=form)