Beispiel #1
0
def userinfo(request):
    """Info about a user

    Return info of current logged in user, or specified user.

    GET parameters:
    sessionid -- session ID obtained at login
    userid -- (optional) user ID
    fwed -- (optional) set to 1 to also return followed users
    fwers -- (optional) set to 1 to also return followers
    ftags -- (optional) set to 1 to also return followed tags
    
    Return values:
    code 0: success, data contains keys:
        user -- User detail object
        fwed -- (optional) followed users (List of Users)
        fwers -- (optional) followers (List of Users)
        ftags -- (optional) followed tags (List of Tags)
    """
    login_required(request)
    user_id = request.GET.get('userid')
    if user_id:
        user = interface.get_user_by_id(user_id)
    else:
        user = request.user
    data = {}
    data['user'] = {
        'name': user.username,
        'id': user.id,
        'email': user.email,
        'full_name': user.userprofile.full_name,
        }
    if request.GET.get('fwed'):
        qs = interface.get_followed_users(user)
        users = [{"id": x.id, "name": x.username} for x in qs]
        data['fwed'] = {"rows": len(users), "users": users}
    if request.GET.get('fwers'):
        qs = interface.get_followers(user)
        users = [{"id": x.id, "name": x.username} for x in qs]
        data['fwers'] = {"rows": len(users), "users": users}
    if request.GET.get('ftags'):
        qs = interface.get_followed_tags(user)
        tags = [x.name for x in qs]
        data['ftags'] = {"rows": len(tags), "tags": tags}
    return my_response(make_response(0, data=data))
Beispiel #2
0
def followers(request):
    """List followers of a user

    List users following a specified (or current) user.

    GET parameters:
    sessionid -- session ID obtained at login
    userid -- (optional) ID of user to list his followers

    Return values:
    code 0: success, data contains List of Users
    """
    login_required(request)
    user_id = request.GET.get('userid')
    if user_id:
        user = interface.get_user_by_id(user_id)
    else:
        user = request.user
    qs = interface.get_followers(user)
    users = [{"id": x.id, "name": x.username} for x in qs]
    return my_response(make_response(0, data = {
        "rows": len(users), "users": users}))