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)
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 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)
def validate_bid_amount(form, field, demand_id): """ Custom validator for BidForm. Validates if bid_amount is less than the lowest bid, if there is any. Also validates that bid_amount is a positive number. """ bids = Bid.get_bids_for_demand(demand_id) if len(bids) > 0: lowest_bid_amount = Bid.get_info(bids[0]).bid_amount if float(field.data) >= float(lowest_bid_amount): print(field.data) raise ValidationError( 'Bid must be lower than the currently lowest bid.')
def my_projects(): """ The '/dashboard/projects' route directs a user to view their projects. """ if 'username' in session: if not session['type_of_user'] == "user": return render_template("access_denied.html") user_type = User.get_user_info(session['username'])['type_of_user'] current = list( Demand.get_info(x) for x in Demand.get_current_projects(session['username'])) mid = [] completed = [] if user_type == "developer": bids_by_username = Bid.get_bids_by_username(session['username']) temp = [] for i in bids_by_username: info = Bid.get_info(i)['demand_id'] if info not in temp: temp.append(info) mid = list(Demand.get_info(y) for y in temp) completed = list( Demand.get_info(x) for x in Developer.get_past_projects(session['username'])) else: temp = (Demand.get_info(x) for x in Demand.get_filtered_demands( None, None, session['username'], None, None, None, True)) for demand in temp: if demand['chosen_developer_username'] is np.nan: mid.append(demand) completed = list( Demand.get_info(x) for x in Client.get_past_projects(session['username'])) return render_template("myProjects.html", user_type=user_type, current=current, mid=mid, completed=completed) else: return redirect(url_for('login'))