Пример #1
0
def upload_system(demand_id):
    """
    The '/bid/<demand_id>/upload-system' route is where the developer can upload the system that
    they have created for a demand they have been chosen for.
    """
    form = SubmitSystemForm()
    demand_info = Demand.get_info(demand_id)
    client = demand_info['client_username']

    if request.method == 'POST':
        if form.validate():
            # will not actually store the file
            # project is now completed
            Developer.submit_system(demand_id, session['username'])
            return redirect(
                url_for('rating', demand_id=demand_id, recipient=client))
        else:
            return render_template("upload_system.html",
                                   demand_id=demand_id,
                                   form=form)

    if request.method == 'GET':
        return render_template("upload_system.html",
                               demand_id=demand_id,
                               form=form)
Пример #2
0
def user(name):
    """
    The '/user/<name>' route directs a user to the profile page of the user with the username
    of [name].
    """
    # if User.has_user_id(name):
    # get basic info
    info = User.get_user_info(name)

    if info['type_of_user'] == 'client':
        rating = Client.get_info(name)['avg_rating']
        projects = Client.get_projects_posted(name)
    elif info['type_of_user'] == 'developer':
        rating = Developer.get_info(name)['avg_rating']
        projects = Developer.get_past_projects(name)

    projects_info = []

    for demand_id in projects:
        projects_info.append(Demand.get_info(demand_id))

    # round rating to the nearest 0.5
    rating = round(0.5 * round(float(rating) / 0.5), 1)
    has_half_star = rating % 1 == .5

    return render_template("profile.html",
                           info=info,
                           rating=int(rating),
                           half_star=has_half_star,
                           projects=projects_info)
Пример #3
0
def browse():
    """
    The '/browse' route directs anyone on the website to a page where they can browse the 
    demands in the system.
    """
    start_date = request.args.get('start_date', default=None, type=str)
    end_date = request.args.get('end_date', default=None, type=str)
    client = request.args.get('client', default=None, type=str)

    client_rating = None
    for i in range(1, 5):
        if request.args.get('rating' + str(i)) == 'on':
            client_rating = i
            break

    tags = request.args.get('tags', default=None, type=str)
    min_bid = request.args.get('min_bid', default=None, type=float)
    active = request.args.get('show_active', default=False)

    demands = Demand.get_filtered_demands(start_date=start_date,
                                          end_date=end_date,
                                          client=client,
                                          client_rating=client_rating,
                                          tags=tags,
                                          min_bid=min_bid,
                                          active=active)
    demands_info = []
    for demand in demands:
        demands_info.append(Demand.get_info(demand))

    return render_template("browse.html", demands_info=demands_info)
Пример #4
0
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'))
Пример #5
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)
Пример #6
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)
Пример #7
0
def rating(demand_id, recipient):
    """
    The '/bid/<demand_id>/rating/<recipient>' route is where the user can rate another user 
    for a demand they were involved in.
    """
    if 'username' not in session:
        return redirect(url_for('login'))

    demand_info = Demand.get_info(demand_id)

    # make sure the user is authorized to rate the recipient
    if session['role'] == 'developer':
        # developer rates the client, so client is recipient
        if session['username'] != demand_info['chosen_developer_username']:
            return render_template('access_denied.html')
    elif session['role'] == 'client':
        # client rates the developer, so developer is recipient
        if session['username'] != demand_info['client_username']:
            return render_template('access_denied.html')

    if Rating.check_if_valid_rating_form(int(demand_id), recipient,
                                         session['username']):
        form = RatingForm()

        if request.method == "GET":
            return render_template("rating.html",
                                   form=form,
                                   recipient=recipient,
                                   demand_id=demand_id)
        elif request.method == "POST":
            # low rating
            if form.rating.data <= 2:
                session['rating' + demand_id] = form.rating.data
                return redirect(
                    url_for('ratingMessage',
                            demand_id=demand_id,
                            recipient=recipient))
            elif form.rating.data == None:
                return render_template('rating.html',
                                       form=form,
                                       recipient=recipient,
                                       demand_id=demand_id)
            else:
                # add to form data
                Rating(demand_id, recipient, session['username'],
                       form.rating.data)

                # if the client gave a good rating to a developer (<= 3)
                # the remaining half of the bid amount gets transferred over to the developer
                if session['role'] == 'client':
                    bid_amount = Demand.get_info(
                        demand_id)['chosen_bid_amount']
                    Transaction(recipient, session['username'],
                                round(bid_amount / 2, 2))

                    # update developer's earnings
                    Developer.add_earnings(recipient, bid_amount)

                return render_template('ratingFinished.html',
                                       recipient=recipient)
    return render_template('access_denied.html')