예제 #1
0
def get_info(package):
    """process the request of getting user's info
    """
    params = package.get('params')
    username = params.get(ParamType.UsernameWithDefault)
    if username is None:
        user = package.get('user')
    else:
        user = UserHelper.get_user_by_username(username)
    if user is None:
        return Response.error_response("No User")

    user = UserHelper.user_filter(user)
    permission_public = user.get('permission')
    user_id = user.get('id')
    school_id = PermissionHelper.get_user_school(user_id)
    if school_id == 0:
        if permission_public >= 8:
            permission_private = permission_public
        else:
            permission_private = -1
        schoolname = 'public area'
    else:
        permission_private = PermissionHelper.get_permission(
            user_id, school_id)
        school = SchoolHelper.get_school(school_id)
        if school is None:
            schoolname = '-'
        else:
            schoolname = school.get('schoolname')

    download = ProgramHelper.count_user_downloadlog(user_id)

    del user['permission']
    user.update({
        'school_name': schoolname,
        'permission_public': permission_public,
        'permission_private': permission_private,
        'download': download
    })
    return Response.success_response({'user': user})
예제 #2
0
def getlist(package):
    #pylint: disable-msg=too-many-locals
    """process the request of getting user's info
    """
    params = package.get('params')
    show_invalid = params.get(ParamType.ShowInvalid) == 'true'
    manager_first = params.get(ParamType.ManagerFirst) == 'true'
    school_id = int(params.get(ParamType.SchoolId))
    page = params.get(ParamType.Page)

    if page is None:
        page = 1
    page = int(page)

    if school_id == 0:
        user_list = UserHelper.user_list(page, show_invalid, manager_first)
        ret_list = []
        if len(user_list) == 0:
            data = {
                'tot_count': UserHelper.user_count(show_invalid),
                'now_count': 0,
                'user_list': []
            }
            return Response.success_response(data)

        for user in user_list:
            download = ProgramHelper.count_user_downloadlog(user.get('id'))
            ret_list.append({
                'username': user.get('username'),
                'motto': user.get('motto'),
                'permission': user.get('permission'),
                'download': download
            })
            data = {
                'tot_count': UserHelper.user_count(show_invalid),
                'now_count': len(ret_list),
                'user_list': ret_list
            }
        return Response.success_response(data)

    buf_userlist = UserHelper.get_all(show_invalid, manager_first)
    userlist = []

    for user in buf_userlist:
        user_id = user.get('id')
        school = PermissionHelper.get_user_school(user_id)
        if school_id != school:
            continue
        download = ProgramHelper.count_user_downloadlog(user.get('id'))
        permission_private = PermissionHelper.get_permission(user_id, school)
        print('permission private', permission_private)
        userlist.append({
            'username': user['username'],
            'motto': user['motto'],
            'permission': permission_private,
            'download': download
        })
    if len(userlist) < (page - 1) * 20:
        data = {'tot_count': len(userlist), 'now_count': 0, 'user_list': []}
        return Response.success_response(data)
    pagelist = userlist[(page - 1) * 20:page * 20]
    data = {
        'tot_count': len(userlist),
        'now_count': len(pagelist),
        'user_list': userlist,
    }
    return Response.success_response(data)