Ejemplo n.º 1
0
def role_choices():
    uid = g.user.uid
    q = QiInfoRole.query.filter_by().order_by(QiInfoRole.id)
    # 权限约束
    cur_role = QiInfoRole.query.filter(QiInfoRole.id == QiInfoUser.rid,
                                       QiInfoUser.id == uid,
                                       QiInfoUser.is_deleted == 0).first()
    if cur_role.rgroup == ChoicesExItemEnum.NEITHER.value:
        return ResultSuccess(msg='角色信息字典', data=[])
    if not cur_role.rgroup == 0:
        q = q.filter(QiInfoRole.rgroup == cur_role.rgroup,
                     QiInfoRole.rlevel >= cur_role.rlevel)

    role_objs = q.all()
    vms = []
    for role in role_objs:
        vms.append({
            'k': role.id,
            'v': {
                'rcode': role.rcode,
                'rname': role.rname
            }
        })
    # 下拉框扩展
    # choice_type = int(request.args.get('choice_type', 0) if not request.args.get('choice_type') == 'undefined' else 0)
    # if choice_type == ChoicesExTypeEnum.TYPE_NEITHER.value:
    #     vms.append(dict(k=ChoicesExItemEnum.NEITHER.value, v={'rcode': '-', 'rname': '无'}))
    # elif choice_type == ChoicesExTypeEnum.TYPE_ALL.value:
    #     vms.insert(0, dict(k=ChoicesExItemEnum.ALL.value, v={'rcode': '-', 'rname': '全部角色'}))
    # elif choice_type == ChoicesExTypeEnum.TYPE_NEITHER_ALL.value:
    #
    #     vms.insert(0, dict(k=ChoicesExItemEnum.ALL.value, v={'rcode': '-', 'rname': '全部角色'}))
    #     vms.append(dict(k=ChoicesExItemEnum.NEITHER.value, v={'rcode': '-', 'rname': '无'}))
    return ResultSuccess(msg='角色信息字典', data=vms)
Ejemplo n.º 2
0
def role_choices_name():
    # uid = g.user.uid
    q = db_v1.session.query(
        QiInfoRole.id, QiInfoRole.rname).filter(QiInfoRole.is_deleted == 0)
    rvs = q.all()
    vms = []
    for id, rname in rvs:
        vm = dict(k=id, v=rname)
        vms.append(vm)
    return ResultSuccess(msg='角色名称字典', data=vms)
Ejemplo n.º 3
0
def user_get():
    cur_user, cur_role, cur_branch = _get_user_full_info()

    vm = {}
    vm['create_time'] = cur_user.create_time
    vm['id'] = cur_user.id
    vm['nickname'] = cur_user.nickname
    vm['rid'] = cur_role.id
    vm['rname'] = cur_role.rname
    vm['rcode'] = cur_role.rcode
    vm['bid'] = cur_branch.id
    vm['branch_name'] = cur_branch.branch_name
    vm['branch_code'] = cur_branch.branch_code

    return ResultSuccess(msg='个人用户信息', data=vm)  # 都有id,注意merge顺序
Ejemplo n.º 4
0
def branch_get_sub(bid):
    branch_all = QiInfoBranch.query.filter_by(
        QiInfoBranch.is_deleted == 0).all()
    branch_dict = {branch.id: branch for branch in branch_all}

    branch_id_pairs = [(branch.id, branch.superior_id)
                       for branch in branch_all]
    branch_all_sub = _branch_sub_rel_reformer(branch_id_pairs, max_deep=10)

    vms = []
    for bid in branch_all_sub.get(int(bid), []):
        if branch_dict.get(bid):
            vms.append(dict(branch_dict[bid]))

    return ResultSuccess(msg='部门层级字典', data=vms)
Ejemplo n.º 5
0
def branch_cascade():
    rvs = QiInfoBranch.query.filter_by(QiInfoBranch.is_deleted == 0).all()

    p_cascade_map = {}
    for rv in rvs:
        parent_id = rv['superior_id']
        p_cascade_item = p_cascade_map.get(parent_id, [])
        child = dict(
            id=rv['id'],
            name=rv['branch_name'],
            # level=rv['level']
        )
        p_cascade_item.append(child)
        p_cascade_map[parent_id] = p_cascade_item
    res = _branch_iter(p_cascade_map, 0)

    return ResultSuccess(msg='部门层级字典', data=res)
Ejemplo n.º 6
0
def token_get_info():
    form = TokenForm().validate_for_api()
    s = Serializer(current_app.config['SECRET_KEY'])
    try:
        data = s.loads(form.token.data, return_header=True)
    except SignatureExpired:
        raise AuthFailed(msg='Token不合法', error_code=4011)
    except BadSignature:
        raise AuthFailed(msg='Token过期', error_code=4012)

    r = {
        'scope': data[0]['scope'],
        'create_at': data[1]['iat'],
        'expire_in': data[1]['exp'],
        'uid': data[0]['uid'],
    }

    return ResultSuccess(data=r)
Ejemplo n.º 7
0
def op_reason_trend():
    _list_per_data_filter_01()
    item = []
    return ResultSuccess(msg='质检概况列表和饼图', data=item)