Ejemplo n.º 1
0
def render_messages_edit(message_id, form):

    m = Message.query.get(message_id)
    auction_id = m.auction_id
    html_file = "auctions/view.html"
    a = Auction.query.get(auction_id)
    seller = User.query.get(a.account_id)
    bids = Bid.find_bids(auction_id)
    highest_bid = Bid.highest_bid(auction_id)
    messages = Message.get_messages(auction_id)
    ended = 0
    if a.date_ends < datetime.datetime.now():
        ended = 1
    time_to_go = a.date_ends - datetime.datetime.now()

    return render_template(html_file,
                           form=form,
                           edit_mode=1,
                           edit_message_id=m.id,
                           seller=seller,
                           bids=bids,
                           highest_bid=highest_bid,
                           ended=ended,
                           days_to_go=time_to_go.days,
                           messages=messages,
                           auction=a)
Ejemplo n.º 2
0
def messages_create(auction_id):

    html_file = "auctions/view.html"
    a = Auction.query.get(auction_id)
    form = BiddingForm(request.form)

    invalid = False
    if not form.message.validate(form):
        invalid = True

    seller = User.query.get(a.account_id)
    bids = Bid.find_bids(auction_id)
    highest_bid = Bid.highest_bid(auction_id)
    messages = Message.get_messages(auction_id)
    ended = 0
    if a.date_ends < datetime.datetime.now():
        ended = 1
    time_to_go = a.date_ends - datetime.datetime.now()

    if invalid:
        return render_template(html_file,
                               form=form,
                               edit_mode=0,
                               seller=seller,
                               bids=bids,
                               highest_bid=highest_bid,
                               ended=ended,
                               days_to_go=time_to_go.days,
                               messages=messages,
                               auction=a)

    m = Message(auction_id, current_user.id, form.message.data)
    db.session().add(m)
    db.session().commit()

    return redirect(url_for("auctions_view", auction_id=auction_id))
Ejemplo n.º 3
0
def auctions_view(auction_id):

    html_file = "auctions/view.html"

    a = Auction.query.get(auction_id)
    seller = User.query.get(a.account_id)
    bids = Bid.find_bids(auction_id)
    highest_bid = Bid.highest_bid(auction_id)
    messages = Message.get_messages(auction_id)
    ended = 0
    if a.date_ends < datetime.datetime.now():
        ended = 1

    time_to_go = a.date_ends - datetime.datetime.now()

    if request.method == "GET":
        return render_template(html_file,
                               form=BiddingForm(),
                               edit_mode=0,
                               edit_message_id=0,
                               seller=seller,
                               bids=bids,
                               highest_bid=highest_bid,
                               ended=ended,
                               days_to_go=time_to_go.days,
                               messages=messages,
                               auction=a)

    form = BiddingForm(request.form)
    invalid = False
    biderror = ""

    if not form.amount.validate(form):
        invalid = True
    elif current_user.id == a.account_id:
        invalid = True
        biderror = "You can not bid in your own auction."
    elif a.minimum_bid > form.amount.data:
        invalid = True
        biderror = "You must bid at least the minimum bid."
    elif highest_bid.get("amount") >= form.amount.data:
        invalid = True
        biderror = "You must bid more than the current highest bid."

    if invalid:
        return render_template(html_file,
                               form=form,
                               edit_mode=0,
                               edit_message_id=0,
                               seller=seller,
                               bids=bids,
                               highest_bid=highest_bid,
                               ended=ended,
                               days_to_go=time_to_go.days,
                               messages=messages,
                               auction=a,
                               biderror=biderror)

    b = Bid(auction_id, current_user.id, form.amount.data)

    db.session().add(b)
    db.session().commit()

    bids = Bid.find_bids(auction_id)
    highest_bid = Bid.highest_bid(auction_id)

    return redirect(url_for("auctions_view", auction_id=auction_id))