Esempio n. 1
0
def find_friends(request):
    friend_usernames = []
    if request.user['is_authenticated']:
        friend_usernames = cass.get_friend_usernames(
            request.session['username']) + [request.session['username']]
    q = request.GET.get('q')
    result = None
    searched = False
    if q is not None:
        searched = True
        try:
            result = cass.get_user_by_username(q)
            result = {
                'username': result.username,
                'friend': q in friend_usernames
            }
        except cass.DatabaseError:
            pass
    context = {
        'q': q,
        'result': result,
        'searched': searched,
        'friend_usernames': friend_usernames,
    }
    return render_to_response(
        'users/add_friends.html', context, context_instance=RequestContext(request))
Esempio n. 2
0
def userline(request, username=None):
    try:
        user = cass.get_user_by_username(username)
    except cass.DatabaseError:
        raise Http404

    # Query for the friend ids
    friend_usernames = []
    if request.user['is_authenticated']:
        friend_usernames = cass.get_friend_usernames(username) + [username]

    # Add a property on the user to indicate whether the currently logged-in
    # user is friends with the user
    is_friend = username in friend_usernames

    start = request.GET.get('start')
    tweets, next_timeuuid = cass.get_userline(username, start=start, limit=NUM_PER_PAGE)
    context = {
        'user': user,
        'username': username,
        'tweets': tweets,
        'next': next_timeuuid,
        'is_friend': is_friend,
        'friend_usernames': friend_usernames,
    }
    return render_to_response(
        'tweets/userline.html', context, context_instance=RequestContext(request))
Esempio n. 3
0
def find_friends(request):
    friend_usernames = []
    if request.user['is_authenticated']:
        friend_usernames = cass.get_friend_usernames(
            request.session['username']) + [request.session['username']]
    q = request.GET.get('q')
    result = None
    searched = False
    if q is not None:
        searched = True
        try:
            result = cass.get_user_by_username(q)
            result = {
                'username': result.username,
                'friend': q in friend_usernames
            }
        except cass.DatabaseError:
            pass
    context = {
        'q': q,
        'result': result,
        'searched': searched,
        'friend_usernames': friend_usernames,
    }
    return render_to_response('users/add_friends.html',
                              context,
                              context_instance=RequestContext(request))
Esempio n. 4
0
def userline(request, username=None):
    try:
        user = cass.get_user_by_username(username)
    except cass.DatabaseError:
        raise Http404

    # Query for the friend ids
    friend_usernames = []
    if request.user['is_authenticated']:
        friend_usernames = cass.get_friend_usernames(username) + [username]

    # Add a property on the user to indicate whether the currently logged-in
    # user is friends with the user
    user['friend'] = username in friend_usernames

    start = request.GET.get('start')
    tweets, next = cass.get_userline(username, start=start, limit=NUM_PER_PAGE)
    context = {
        'user': user,
        'username': username,
        'tweets': tweets,
        'next': next,
        'friend_usernames': friend_usernames,
    }
    return render_to_response('tweets/userline.html',
                              context,
                              context_instance=RequestContext(request))
def reset_friends():
    for user in USERS:
        # Remove all friends
        for friend in get_friend_usernames(user):
            remove_friend(user, friend)
        # Add some new friends
        for i in range(randint(1, len(USERS)-1)):
            add_friends(user, [choice(USERS)])