예제 #1
0
파일: job.py 프로젝트: JelteF/bottor
def create():
    """ Create new job """
    matrixA = Matrix.by_id(request.json['A'])
    matrixB = Matrix.by_id(request.json['B'])
    JobController.create(matrixA, matrixB)

    return jsonify()
예제 #2
0
def get_student_txs(userindex):
    if userindex.Role != UserRole.Student:
        abort(403, u"只有学生可以查询")
    l = list()
    for jobid, txid in userindex.JobTxMap.items():
        job = JobController.get_job_by_jobid(jobid)
        # TODO check with front end
        if job is not None:
            d = job.dump_to_dict()
            # TODO wait for check
            txs = d.pop("Txs")
            d["Tx"] = TxController.get_tx_by_txid(txid).dump_to_dict()
            l.append(d)
    l.sort(key=lambda x: x["Tx"]["Time"], reverse=True)

    data = get_data_from_ajax()
    state = data.get("State", None)
    if state is not None:
        try:
            state = int(state)
            if not (0 <= state <= 4):
                abort(400, "State 只能是 0,1,2,3,4")
        except ValueError, e:
            abort(400, "State 只能是数字")
        ret = list()
        for t in l:
            if t["Tx"]['State'] == state:
                ret.append(t)
        return return_data(data=ret)
예제 #3
0
def agency_check(userindex):
    if userindex.Role != UserRole.Agency:
        abort(403, u"只有中介可以检查")
    data = get_data_from_ajax()
    txid = data.get("TxID", None)
    result = data.get("Result", None)
    if txid is None or result is None:
        abort(400, u"缺少 TxID 或 Result")
    # tx = Tx.from_blockchain(txid)
    tx = TxController.get_tx_by_txid(txid)
    if tx is None:
        abort(403, u"提供的tx: %s 不存在" % txid)

    result = unicode(result)
    if result not in [u"1", u"2"]:
        abort(403, u"result only can be: 1 or 2")
    # tx.bc_artificial_check(result)
    # lookup
    # tx = Tx.from_blockchain(txid)
    job = JobController.get_job_by_jobid(tx.JobID)
    if result == u"1":
        job.TotalHired += 1
        job.TotalWaitCheck -= 1
        tx.Status = u"已通过"

    else:
        tx.Status = u"未通过"
        job.TotalWaitCheck -= 1

    job.save()
    tx.save()

    return return_data(data=tx.dump_to_dict())
예제 #4
0
def student_apply(userindex):
    data = get_data_from_ajax()
    JobID = data.get("JobID", None)
    if JobID is None:
        abort(400, u"缺少 JobID")

    if JobID in userindex.JobTxMap.keys():
        tx = Tx.from_blockchain(unicode(userindex.JobTxMap[JobID]))
        if tx is not None:
            tx.save()
            print "tx from existed data!"
            return return_data(data=tx.dump_to_dict())

    tx = TxController.create_tx(userindex.UserID, JobID)
    # add tx status re-get
    new_tx = Tx.from_blockchain(unicode(tx.id))
    if new_tx is None:
        abort(403, u"创建 %s 没有成功" % tx.id)
    new_tx.save()

    job = JobController.get_job_by_jobid(jobid=JobID)
    if job is not None:
        job.TotalApplied += 1
        job.save()
        userindex.JobTxMap[JobID] = unicode(new_tx.id)  # {jobid: txid}
        userindex.save()

    return return_data(data=new_tx.dump_to_dict())
예제 #5
0
파일: views.py 프로젝트: JelteF/bottor
def job():
    jobs = JobController.get_all()
    for job in jobs:
        print(job.matrixA)
        print(job.matrixB)
    return render_template('job.htm', data={
        'jobs': jobs,
    })
예제 #6
0
def student_apply(userindex):
    data = get_data_from_ajax()
    JobID = data.get("JobID", None)
    if JobID is None:
        abort(400, u"缺少 JobID")

    if JobID in userindex.JobTxMap.keys():
        tx = Tx.from_blockchain(unicode(userindex.JobTxMap[JobID]))
        if tx is not None:
            tx.save()
            print "tx from existed data!"
            return return_data(data=tx.dump_to_dict())

    tx = TxController.create_tx(userindex.UserID, JobID)

    # tx.save()
    # add tx status re-get
    # new_tx = Tx.from_blockchain(unicode(tx.id))
    # if new_tx is None:
    #     abort(403, u"创建 %s 没有成功" % tx.id)
    # new_tx.save()

    job = JobController.get_job_by_jobid(jobid=JobID)
    if job is not None:
        job.TotalApplied += 1
        job.Txs.append(tx)

        # 自动审核通过
        if userindex.CurrentCreditScore > 8:
            tx.Status = u"已通过"
            print("当前信用分数:")
            print(userindex.CurrentCreditScore)
            job.TotalHired += 1
        else:  # 自动审核未通过
            tx.Status = u"未通过"
            job.TotalWaitCheck += 1

        job.save()
        tx.save()
        userindex.JobTxMap[JobID] = unicode(tx.id)  # {jobid: txid}

        print "job dump to dict"
        print job.dump_to_dict()
        print "user job tx map"
        print userindex.JobTxMap
        userindex.save()

        u = UserController.get_user_byuserid(userindex.UserID)
        u.JobIDs.append(unicode(job.id))  # 注意这个 待会测一下
        u.save()

    return return_data(data=tx.dump_to_dict())
예제 #7
0
def get_all_jobs():
    l = JobController.get_all_agency_and_jobs()
    ret = list()
    for i in l:  # i is agencyindex
        count = 0
        name = unicode(i[0])
        score = float(i[1])
        for job in reversed(i[2]):
            if count > 5:
                break
            ret.append({"AgencyName": name, "Score": score, "JobInfo": job})
            count += 1
    return return_data(data=ret)
예제 #8
0
def get_all_jobs_by_time():
    jobs = JobController.get_all_jobs_by_time()
    ret = list()
    max_count = 20
    max_count = max_count if max_count < len(jobs) else len(jobs)
    for i in range(max_count):
        job = jobs[i]
        print job.PublishTime
        userindex = UserController.get_userindex_byuserid(job.UserID)
        if userindex is not None:
            ret.append({"AgencyName": userindex.AgencyName, "Score": userindex.CurrentCreditScore,
                        "JobInfo": job.dump_to_dict()})

    return return_data(data=ret)
예제 #9
0
def user_agency():
    data = get_data_from_ajax()
    jobid = data.get("JobID", None)
    if jobid is None:
        abort(400, "缺少 JobID")

    jobinfo = JobController.get_job_by_jobid(jobid)
    if jobinfo is None:
        abort(403, "查询的 JobID: %s 不存在" % jobid)

    userindex = UserController.get_userindex_byuserid(jobinfo.UserID)
    d = userindex.dump_to_dict()
    d["Score"] = userindex.CurrentCreditScore
    d["JobsCount"] = len(userindex.JobTxMap)
    return return_data(None, data=d)
예제 #10
0
def job_query():
    data = get_data_from_ajax()
    jobid = data.get("JobID", None)
    if jobid is None:
        abort(400, "缺少 JobID")

    # job = JobInfo.from_blockchain(jobid)
    job = JobController.get_job_by_jobid(jobid)
    if job is None:
        abort(403, u"没有查找到对应JobID: %s 的兼职信息" % jobid)
    # print type(job.id)
    job.save()

    d = job.dump_to_dict()
    username = data.get("username", None)
    if username is None:
        username = data.get("Username", None)
    if username is not None:
        userindex = UserController.get_userindex_byname(username)
        if userindex is not None:
            if jobid in userindex.JobTxMap.keys():
                d["IsApplied"] = True
            else:
                d["IsApplied"] = False

    state = data.get("State", None)
    if state is not None:
        try:
            state = int(state)
            if not (0 <= state <= 4):
                abort(400, "State 只能是 0,1,2,3,4")
        except ValueError, e:
            abort(400, "State 只能是数字")
        txs = d["Txs"]
        l = list()
        for t in txs:
            if t['State'] == state:
                l.append(t)
        d["Txs"] = l
예제 #11
0
    check_list.append(place)
    check_list.append(salary)
    check_list.append(day)
    check_list.append(demand)

    if check_list.count(None):
        abort(400, u"缺少参数%d" % check_list.index(None))

    try:
        s = int(salary)
        if s <= 0 or s > 65535:
            abort(400, u"Salary 设置不合理")
    except ValueError, e:
        abort(400, u"Salary 必须是一个整数")

    job = JobController.create_jobinfo(userindex, title, jobtime, place,
                                       salary, day, demand)
    userindex.JobTxMap[unicode(job.id)] = ""
    userindex.save()

    u = UserController.get_user_byuserid(userindex.UserID)
    u.JobIDs.append(unicode(job.id))  # 注意这个 待会测一下
    u.save()

    return return_data(data=job.dump_to_dict())


@app.route('/job/agency/jobs', methods=['GET', 'POST'])
@allow_cross_domain
@check_auth
def get_agency_jobs(userindex):
    """
예제 #12
0
        abort(403, u"提供的tx: %s 不存在" % txid)

    # tx.bc_evaluate(userid, score)
    # return tx state
    # lookup
    # tx = Tx.from_blockchain(txid)
    userindex.TotalCreditScore += score
    userindex.RateCount += 1
    userindex.CurrentCreditScore = int(userindex.TotalCreditScore /
                                       userindex.RateCount)
    userindex.save()

    # 只结算一次钱
    if tx.Status != u"已结算":
        user = UserController.get_user_byuserid(userindex.UserID)
        job = JobController.get_job_by_jobid(tx.JobID)
        salary = int(job.JobDetail.Salary)
        if userindex.Role == 0:  # user is student
            user.Balance += salary
            # get the agency
            agency = UserController.get_user_byuserid(job.UserID)
            agency.Balance -= salary
        else:  # user is agency
            user.Balance -= salary
            # get the student
            st = UserController.get_user_byuserid(tx.UserID)
            st.Balance += salary
        tx.Status = u"已结算"
        tx.save()
    return return_data(data=tx.dump_to_dict())