Exemple #1
0
def branch_add():
    form = BranchAddForm().validate_for_api()
    branch_name = form.branch_name.data
    superior_id = form.superior_id.data
    if QiInfoBranch.query.filter_by(branch_name=branch_name,
                                    superior_id=superior_id).first():
        superior_name = QiInfoBranch.query.filter_by(
            id=superior_id).first().branch_name
        raise ParameterException(msg=superior_name + '已有' + branch_name +
                                 ',如要新建,请重新命名 ')
    branch = QiInfoBranch()
    placeholder_num = current_app.config['BUSI_BRANCH_CODE_PLACEHOLDER_NUM']
    branch_code_list = QiInfoBranch.query.with_entities(
        QiInfoBranch.branch_code).filter_by(with_deleted=True).all()
    branch_cnt = max([
        int(proj_code[-placeholder_num:]) for proj_code, in branch_code_list
    ]) if len(branch_code_list) > 0 else 0
    branch_code = '{}{}'.format(current_app.config['BUSI_BRANCH_CODE_PREFIX'],
                                str(branch_cnt + 1).zfill(placeholder_num))
    with db_v1.auto_commit():
        form.populate_obj(branch)
        branch.insert_time = current_timestamp_sec()
        branch.is_deleted = 0
        branch.branch_code = branch_code
        branch.superior_id = form.superior_id.data
        branch.create_time = current_timestamp_sec()
        db_v1.session.add(branch)
    vm_keys_branch = ('id', 'create_time')
    vm = {}
    for v_key in vm_keys_branch:
        vm[v_key] = getattr(branch, v_key, None)
    vm['create_time'] = vm['create_time']
    return CreateSuccess(msg='部门新增成功', data=vm)
Exemple #2
0
def create_user_api():
    form = CreateUserForm().validate_for_api().data_
    form['nickname'] = form['password'] = form['username']
    form['permission'] = 0
    form['status'] = 1
    User.create(**form)
    raise CreateSuccess('User has been created')
Exemple #3
0
def user_add():
    form = UserAddForm().validate_for_api()
    Role = QiInfoRole.query.filter_by(id=form.rid.data).first_or_404()
    role_code = Role.rcode

    if role_code == 'diremanager' and form.bid.data:
        raise ParameterException(msg='主管人员请不要填写部门')
    if (role_code != 'diremanager' and role_code != 'systemadmin') and form.bid.data is None:
        raise ParameterException(msg='请选择部门')
    if role_code == 'agentoperator' and form.agent_id.data is None:
        raise ParameterException(msg='坐席人员请填写工号')
    if role_code != 'agentoperator' and form.agent_id.data:
        raise ParameterException(msg='非坐席人员,请不要填写工号')
    user = QiInfoUser()

    with db_v1.auto_commit():
        form.populate_obj(user)
        user.insert_time = current_timestamp_sec()
        user.ac_type = 100
        user.ac_status = 100
        user.password = form.password.data
        user.is_deleted = 0
        user.create_time = current_timestamp_sec()
        db_v1.session.add(user)
    vm_keys_user = ('id', 'create_time')
    vm = {}
    for v_key in vm_keys_user:
        vm[v_key] = getattr(user, v_key, None)
    return CreateSuccess(msg='用户新增成功', data=vm)
def modify_competition_api(id_):
    competition = Competition.get_by_id(id_)
    if competition is None:
        raise NotFound('Competition not found')

    form = ModifyCompetitionForm().validate_for_api().data_
    competition.modify(**form)
    raise CreateSuccess('Competition has been modified')
Exemple #5
0
def token_get():
    form = LoginForm().validate_for_api()
    identity = QiInfoUser.verify(form.account.data, form.password.data)

    # gen Token
    expiration = current_app.config['TOKEN_EXPIRATION']
    token = generate_auth_token(identity['uid'], identity['ac_type'],
                                identity['scope'], expiration)
    t = {'token': token.decode('ascii')}

    return CreateSuccess(msg='令牌生成', data=t)
def create_team_api():
    form = TeamInfoForm().validate_for_api().data_
    contest = Contest.get_by_id(form['contest_id'])
    if contest.status == 0:
        raise Forbidden('Contest is not available')
    if contest.registration_status == 0:
        raise Forbidden('Contest is not open registration')
    for i in TeamRelationship.search(username=g.user.username)['data']:
        if i.team.contest.id == form['contest_id']:
            raise Forbidden('You already have a team')

    team = Team.create_team(form['name'], form['contest_id'], g.user.username, form['password'])
    TeamRelationship.create_team_relationship(g.user.username, team.id)
    return CreateSuccess('Create team success')
def create_team_relationship_api():
    form = TeamRelationshipForm().validate_for_api().data_
    team = Team.get_by_id(form['team_id'])
    if not team:
        raise NotFound()
    contest = team.contest
    if contest.status == 0:
        raise Forbidden('Contest is not available')
    if contest.registration_status == 0:
        raise Forbidden('Contest is not open registration')
    for i in TeamRelationship.search(username=g.user.username)['data']:
        if i.team_id == form['team_id']:
            raise Forbidden('You already have a team')
    if TeamRelationship.search(team_id=form['team_id'])['count'] >= team.contest.limit:
        raise Forbidden('The team is full')
    if not team.check_password(form['password']):
        raise Forbidden('Password wrong')

    TeamRelationship.create_team_relationship(g.user.username, form['team_id'])
    return CreateSuccess('Create team relationship success')
Exemple #8
0
def create_task_api():
    form = CreateTaskForm().validate_for_api().data_
    if form['type'] == 'crawl_user_info':
        if form['kwargs']:
            submit_crawl_accept_problem_task(form['kwargs']['username'], form['kwargs']['oj_id'])
        else:
            submit_crawl_accept_problem_task()
    elif form['type'] == 'crawl_problem_info':
        submit_crawl_problem_rating_task(form['kwargs']['problem_id'])
    elif form['type'] == 'crawl_course_info':
        if form['kwargs']:
            submit_crawl_course_info_task(form['kwargs']['course_id'])
        else:
            submit_crawl_course_info_task()
    elif form['type'] == 'calculate_user_rating':
        if form['kwargs']:
            submit_calculate_user_rating_task(form['kwargs']['username'])
        else:
            submit_calculate_user_rating_task()
    return CreateSuccess('Task has been created')
Exemple #9
0
def create_camp_api():
    form = CreateCampForm().validate_for_api().data_
    Camp.create(**form)
    raise CreateSuccess('Course set has been created')
Exemple #10
0
def refresh_all_api():
    submit_crawl_course_info_task()
    raise CreateSuccess('Task has been created')
Exemple #11
0
def create_problem_set_api():
    form = CreateProblemSetForm().validate_for_api().data_
    ProblemSet.create(**form)
    raise CreateSuccess('Problem set has been created')
def create_announcement_api():
    form = AnnouncementInfoForm().validate_for_api().data_
    Announcement.create_announcement(form['contest_id'], form['type'],
                                     form['content'])
    return CreateSuccess('Create announcement success')
def create_competition_api():
    form = CreateCompetitionForm().validate_for_api().data_
    Competition.create(**form)
    raise CreateSuccess('Competition has been created')
Exemple #14
0
def create_contest_api():
    form = ContestInfoForm().validate_for_api().data_
    Contest.create_contest(form['name'], form['limit'])
    return CreateSuccess('Create contest success')
Exemple #15
0
def register_user_api():
    form = RegisterForm().validate_for_api().data_
    _verification(form['uuid'])
    User.register(form['username'], form['password'])
    return CreateSuccess('register successful')