Esempio n. 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)
Esempio n. 2
0
def add(request):
    c = {}
    c.update(csrf(request))
    isvalid = True
    u = Demand
    if request.method == "POST":
        u = Demand()
        member_id = request.POST["member_id"]
        name_en = request.POST["name_en"]
        if member_id == "0" or member_id == "":
            isvalid = False
            messages.warning(request, "please select member")
        if name_en == "":
            isvalid = False
            messages.warning(request, "please input english name")
        # _bind_data(request, u)
        if isvalid:
            try:
                u.save()
                _save_items(request, u)
                return redirect("demand.index")
            except Exception, e:
                messages.warning(request, e.message)
                logging.error(e.message)
                logging.debug(e.message)
Esempio n. 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)
Esempio n. 4
0
def createDemand():
    """
    The '/createDemand' route directs a client to the form where he/she can
    create and post a demand on the Turk System.
    """
    if 'username' not in session:
        return redirect(url_for('login'))

    if session['role'] != 'client':
        return render_template('access_denied.html')

    form = DemandForm()

    if request.method == 'POST':
        if form.validate():
            format = '%m-%d-%Y %I:%M %p'
            dt_bid = form.bidding_deadline.data.strftime(format)
            dt_submit = form.submission_deadline.data.strftime(format)

            Demand(session['username'], form.title.data, form.tags.data,
                   form.specifications.data, dt_bid, dt_submit)
            new_demand_id = Demand.get_most_recent_demand_id()

            return redirect(url_for('bidInfo', demand_id=new_demand_id))
        else:
            return render_template('createDemand.html', form=form)
    elif request.method == 'GET':
        return render_template('createDemand.html', form=form)
Esempio n. 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)
Esempio n. 6
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)
Esempio n. 7
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)
Esempio n. 8
0
def three(request, key):
    objects = Demand.objects(key=key)[0]
    work_year = objects.workYear
    work_year_list = []
    for each in work_year:
        work_year_list.append({'name': each, 'value': work_year[each]})
    position = objects.position
    position_list = []
    for each in position:
        position_list.append({'name': each, 'value': position[each]})
    education = objects.education
    education_list = []
    for each in education:
        education_list.append({'name': each, 'value': education[each]})
    company_stage = objects.companyStage
    company_stage_list = []
    for each in company_stage:
        company_stage_list.append({'name': each, 'value': company_stage[each]})
    render_data = {'work_year': work_year_list,
                   'position': position_list,
                   'education': education_list,
                   'company_stage': company_stage_list}

    return render(request, 'chart03.html', {'key': key,
                                            'data': json.dumps(render_data, encoding="UTF-8", ensure_ascii=False)})
Esempio n. 9
0
def save(request):
    response_data = {}
    response_data['result'] = 'failed'
    if request.method == "POST":
        try:
            name_en = request.POST["name_en"]
            name_cn = request.POST["name_cn"]
            if name_en == "" and name_cn == "":
                response_data['message'] = _("please input demand name")
            else:
                #check stock_symbol is correct
                company_stock_symbol = request.POST.get(
                    "company_stock_symbol", False)
                is_list_company = int(request.POST.get("is_list_company", 0))
                if company_stock_symbol and is_list_company == 1:
                    checksymbolExsit = ListedCompany.objects.filter(
                        stock_symbol=company_stock_symbol)
                    if len(checksymbolExsit) == 0:
                        response_data['message'] = 'symbolNotExsit'
                        return HttpResponse(simplejson.dumps(response_data),
                                            content_type="text/plain")
                submitStatus = request.POST["submitStatus"]
                u = Demand()
                isExsit = False
                id_post = request.POST.get("id", False)
                #check the demand is exsit with member_id
                condition = Q(member_id=request.POST.get("member_id"))
                condition2 = Q()
                if id_post:
                    condition = condition & ~Q(pk=id_post)
                if name_cn.strip() != "":
                    condition2 = condition2 | Q(name_cn=name_cn.strip())

                if name_en.strip() != "":
                    condition2 = condition2 | Q(name_en=name_en.strip())

                project = Demand.objects.filter(condition & condition2)
                if project:
                    isExsit = True
                    response_data['message'] = "demandExsit"

                if isExsit is False:
                    if id_post:
                        u = Demand.objects.get(pk=id_post)
                    # if submitStatus == "draft":
                    #     u.status = StatusDemand.draft
                    # else:
                    #     u.status = StatusDemand.pending
                    bool, msg = _bind_data(request, u)
                    if bool:
                        response_data['result'] = 'success'
                        response_data['id'] = u.id
                        response_data['message'] = '操作成功'
                    else:
                        response_data['message'] = msg

        except Exception, e:
            logger.error(e.message)
            response_data['message'] = e.message
Esempio n. 10
0
def DemandRegister():
    demand = request.get_json()
    db.session.add(
        Demand(field_demands=Field.query.filter_by(
            name=demand['field_name']).first(),
               local_demands=Local.query.filter_by(
                   name=demand['local_name']).first()))
    db.session.commit()
    return Response(status=200, mimetype='application/json')
Esempio n. 11
0
def one(request, key):
    objects = Demand.objects(key=key)[0]
    demand_job = objects.demandJob
    demand_company = objects.demandCompany
    sort_demand_job = sorted(demand_job.items(), lambda x, y: cmp(x[1], y[1]), reverse=True)  # 按招聘职位数量降序
    city = [each[0] for each in sort_demand_job][0:10]
    job_top10 = [each[1] for each in sort_demand_job][0:10]
    company_top10 = [demand_company[each] for each in city]
    data = {'city': city, 'jobTop10': job_top10, 'companyTop10': company_top10}
    return render(request, 'chart01.html',
                  {'key': key,
                   'data': json.dumps(data, encoding="UTF-8", ensure_ascii=False),
                   })
Esempio n. 12
0
def two(request, keys):
    objects = Demand.objects(key=keys)[0]
    demand_job = objects.demandJob
    sort_demand_job = sorted(demand_job.items(), lambda x, y: cmp(x[1], y[1]), reverse=True)
    city = [each[0] for each in sort_demand_job]
    job_number = [each[1] for each in sort_demand_job]
    map_data = []
    for each in city:
        map_data.append({'name': each, 'value': demand_job[each]})
    data_top10 = map_data[0:10]
    max_data = job_number[0]
    data = {'mapData': map_data, 'city': city, 'jobNumber': job_number, 'dataTop10': data_top10, 'maxData': max_data}
    return render(request, 'chart02.html', {'key': keys,
                                            'data': json.dumps(data, encoding="UTF-8", ensure_ascii=False)})
Esempio n. 13
0
    def post(self):
        # client
        # client = Client(name='Joãoson', email='*****@*****.**', password='******')
        # db.session.add(client)
        # print(Client.query.all())

        requestData = request.get_json()
        date = datetime.datetime.strptime(requestData.get('maxDate'), '%d/%m/%Y')
        demand = Demand(name=requestData.get('name'), description=requestData.get('description'), funcionalities=requestData.get('funcionalities'),
                        final_date=date, platform='desktop', client_id='1')
        db.session.add(demand)
        db.session.commit()
        print(Demand.query.all())
        return {'status': 'criada'}
Esempio n. 14
0
    def post(self):

        requestData = request.get_json()
        date = datetime.datetime.strptime(requestData.get('maxDate'),
                                          '%d/%m/%Y')
        demand = Demand(name=requestData.get('name'),
                        description=requestData.get('description'),
                        funcionalities=requestData.get('funcionalities'),
                        final_date=date,
                        platform='desktop',
                        client_id=requestData.get('user_id'))
        db.session.add(demand)
        db.session.commit()
        print(Demand.query.all())
        return {'status': 'criada'}
Esempio n. 15
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)
Esempio n. 16
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'))
Esempio n. 17
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')