예제 #1
0
def justify_developer_choice(demand_id):
    """
    The '/bid/<demand_id>/justify-developer' route is where the client fills out a form
    to explain his/her reason for choosing a developer who did not offer the lowest bid.
    """
    bids = Bid.get_bids_for_demand(demand_id)
    bids_info = []
    bidders_info = {}

    for bid in bids:
        info = Bid.get_info(bid)
        bids_info.append(info)

        if info['developer_username'] not in bidders_info:
            username = info['developer_username']
            bidders_info[username] = User.get_user_info(username)
            bidders_info[username]['lowest_bid'] = info['bid_amount']

    form = JustifyDeveloperChoiceForm()

    if request.method == 'POST':
        if form.validate():
            Demand.choose_developer(
                demand_id, session['chosen_developer'], session['username'],
                bidders_info[session['chosen_developer']]['lowest_bid'],
                form.reason.data)
            return render_template("developer_chosen.html")
        else:
            return render_template("justify_developer_choice.html",
                                   demand_id=demand_id,
                                   form=form)
    if request.method == 'GET':
        return render_template("justify_developer_choice.html",
                               demand_id=demand_id,
                               form=form)
예제 #2
0
def choose_developer(demand_id):
    """
    The '/bid/<demand_id>/choose-developer' route directs a client to a page
    where he/she can select the developer he/she wants to hire to implement the
    system that was demanded.
    """
    demand_info = Demand.get_info(demand_id)

    bids = Bid.get_bids_for_demand(demand_id)
    bids_info = []
    bidders_info = {}

    for bid in bids:
        info = Bid.get_info(bid)
        bids_info.append(info)

        if info['developer_username'] not in bidders_info:
            username = info['developer_username']
            bidders_info[username] = User.get_user_info(username)
            bidders_info[username]['lowest_bid'] = info['bid_amount']

            rating = Developer.get_info(username)['avg_rating']
            # round rating to the nearest 0.5
            rating = round(0.5 * round(float(rating) / 0.5), 1)
            bidders_info[username]['full_stars'] = int(rating)
            bidders_info[username]['has_half_star'] = rating % 1 == .5

    if request.method == 'POST':
        chosen_developer = request.form['developer']
        session['chosen_developer'] = request.form['developer']

        # if the chosen developer had the lowest bid,
        # update the demand's chosen developer
        if chosen_developer == bids_info[0]['developer_username']:
            # updates the table, notifies the developer, and also starts the transaction request
            Demand.choose_developer(demand_id, chosen_developer,
                                    session['username'],
                                    bids_info[0]['bid_amount'])
            return render_template("developer_chosen.html")

        # if the chosen developer did not have the lowest bid,
        # the client must provide a reason for choosing this developer
        else:
            return redirect(
                url_for('justify_developer_choice', demand_id=demand_id))
    if request.method == 'GET':
        return render_template("choose_developer.html",
                               demand_id=demand_id,
                               bidders_info=bidders_info)