コード例 #1
0
ファイル: views.py プロジェクト: soequelle/twissandra
def userline(request, username=None):
    try:
        user = cass.get_user_by_username(username)
    except cass.DatabaseError:
        raise Http404
    
    # Query for the friend ids
    friend_ids = []
    if request.user['is_authenticated']:
        friend_ids = cass.get_friend_ids(request.user['id']) + [request.user['id']]
    
    # Add a property on the user to indicate whether the currently logged-in
    # user is friends with the user
    user['friend'] = user['id'] in friend_ids
    
    start = request.GET.get('start')
    tweets = cass.get_userline(user['id'], start=start, limit=NUM_PER_PAGE + 1)
    next = None
    if tweets and len(tweets) == NUM_PER_PAGE + 1:
        next = tweets[-1]['_ts']
    tweets = tweets[:NUM_PER_PAGE]
    
    context = {
        'user': user,
        'tweets': tweets,
        'next': next,
        'friend_ids': friend_ids,
    }
    return render_to_response('tweets/userline.html', context,
        context_instance=RequestContext(request))
コード例 #2
0
ファイル: views.py プロジェクト: soequelle/twissandra
def find_friends(request):
    friend_ids = []
    if request.user['is_authenticated']:
        friend_ids = cass.get_friend_ids(request.user['id']) + [
            request.user['id']]
    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['friend'] = result['id'] in friend_ids
        except cass.DatabaseError:
            pass
    context = {
        'q': q,
        'result': result,
        'searched': searched,
        'friend_ids': friend_ids,
    }
    return render_to_response('users/add_friends.html', context,
        context_instance=RequestContext(request))