def ajax_timeline(request): g = request.GET if not request.user.is_authenticated() or 'twitter_tokens' not in request.session: return HttpResponseBadRequest('not authenticated') twitter_tokens = request.session['twitter_tokens'] api = get_authorized_twython(twitter_tokens) tp = TwitterUserProfile.objects.get(id=twitter_tokens['user_id']) if not g.has_key(u'page'): return HttpResponseBadRequest('page number missing') page, feedtype = int(g[u'page']), g[u'timeline'] # Get maxid for certain types of timelines try: maxid = int(g[u'id']) except KeyError: maxid = None # Force cache fill if no statuses loaded originally if page == 1: cache_timeline_backfill(tp, twitter_tokens, None) if feedtype == 'normal': statuses = normal_timeline(api, tp, page, maxid) elif feedtype == 'reorder': statuses = reorder_timeline(api, tp, page) elif feedtype == 'filter': statuses = filter_timeline(api, tp, page, maxid) elif feedtype == 'predict': statuses = predict_timeline(api, tp, page, maxid) if len(statuses) == 0: return HttpResponse('Loading') Rating.appendTo(statuses, tp) return render_to_response('twitter/status_list.html', { 'statuses': statuses }, context_instance=RequestContext(request))
def timeline(request): user = request.user if not user.is_authenticated() or 'twitter_tokens' not in request.session: return render_to_response('landing.html') twitter_tokens = request.session['twitter_tokens'] tp = TwitterUserProfile.objects.get(id=twitter_tokens['user_id']) api = get_authorized_twython(twitter_tokens) statuses = Status.construct_from_dicts(api.getFriendsTimeline(include_rts=True)) cache_timeline_backfill.delay(tp, twitter_tokens, statuses) friends = api.getFriendsStatus() Rating.appendTo(statuses, tp) return render_to_response('twitter/timeline.html', { 'statuses': statuses, 'friends': friends, 'feedtype': 'normal' }, context_instance=RequestContext(request))
def search(request): if not request.user.is_authenticated() or 'twitter_tokens' not in request.session: return HttpResponseRedirect("/") term = request.GET.get('q') if term is not None: prof = request.user.get_profile() twitter_tokens = request.session['twitter_tokens'] api = get_authorized_twython(twitter_tokens) tp = TwitterUserProfile.objects.get(id=twitter_tokens['user_id']) statuses = Status.construct_from_search_dicts(api.searchTwitter(q=term)[u'results']) friends = api.getFriendsStatus() Rating.appendTo(statuses, tp) return render_to_response('twitter/search_index.html', { # 'whale': prof.whale, 'friends': friends, 'statuses': statuses, 'term': term }, context_instance=RequestContext(request)) else: return HttpResponseRedirect("/")
def public_profile(request, username): if request.user.is_authenticated() and 'twitter_tokens' in request.session: twitter_tokens = request.session['twitter_tokens'] api = get_authorized_twython(twitter_tokens) else: # Require login return HttpResponseRedirect("/") friend = api.showUser(screen_name=username) friends = api.getFriendsStatus() prof = request.user.get_profile() tp = TwitterUserProfile.objects.get(user=prof) follow_request_sent = True is_true_friend = friend['following'] is_me = tp.id == friend['id'] if not is_true_friend: is_true_friend = False outgoing = api.friendshipsOutgoing() follow_request_sent = False if friend['id'] in outgoing['ids']: # if we have already requested to follow this person follow_request_sent = True if friend['protected'] and not is_true_friend: statuses = None else: try: statuses = Status.construct_from_dicts(api.getUserTimeline(screen_name=username)) Rating.appendTo(statuses, tp) except TwythonError: statuses = None return render_to_response('twitter/public_profile.html', { 'friends': friends, 'username': username, 'friend': friend, 'is_true_friend' : is_true_friend, 'is_me' : is_me, 'profile_protected' : friend['protected'], 'follow_request_sent': follow_request_sent, 'statuses' : statuses, }, context_instance=RequestContext(request))