Skip to content

Commit

Permalink
social only displays friends
Browse files Browse the repository at this point in the history
  • Loading branch information
imkevinxu committed Jun 9, 2013
1 parent 92f1ecc commit a47b78e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
5 changes: 5 additions & 0 deletions prototype/facebook/models.py
Expand Up @@ -28,6 +28,11 @@ def get_facebook_profile(self):
fb_profile = urllib.urlopen('https://graph.facebook.com/me?access_token=%s' % self.access_token)
return json.load(fb_profile)

def get_facebook_friends(self):
fb_friends = urllib.urlopen('https://graph.facebook.com/me/friends?access_token=%s' % self.access_token)
json_friends = json.load(fb_friends)['data']
return [f['id'] for f in json_friends]

def _average_mpg(self):
drives = Drive.objects.filter(fb=self)
if len(drives) == 0: return 0
Expand Down
4 changes: 2 additions & 2 deletions prototype/prototype_app/views.py
Expand Up @@ -125,7 +125,7 @@ def dashboard(request):
# last_trip_duration = ("%d" % (last_trip[1].seconds/3600), "%d" % (last_trip[1].seconds%3600/60))
# last_trip_fuel = last_trip[2]

friends = [user for user in FacebookProfile.objects.all() if 'error' not in user.get_facebook_profile()]
friends = [user for user in FacebookProfile.objects.all() if str(user.facebook_id) in fb.get_facebook_friends()]

return render(request, 'dashboard.html', locals())
#return render_to_response('index.html', {'facebook_profile': facebook_profile}, context_instance=RequestContext(request))
Expand All @@ -148,7 +148,7 @@ def challenge(request):
bet = request.POST['bet']
c = Challenge(challenger=fb, challengee=challengee, bet=bet)
c.save()
fb.coins = fb.coins - bet
fb.coins = fb.coins - int(bet)
fb.save()

return redirect('/dashboard')
Expand Down

0 comments on commit a47b78e

Please sign in to comment.