Skip to content
Browse files

added get all favs

  • Loading branch information...
1 parent a1477a7 commit 70f1389673dfde224c01b1942e08d2b6f0c94d6a @bzhang63 bzhang63 committed Mar 31, 2012
Showing with 19 additions and 0 deletions.
  1. +1 −0 urls.py
  2. +8 −0 users/models.py
  3. +10 −0 users/views.py
View
1 urls.py
@@ -30,4 +30,5 @@
url(r'^events/getmatches/', 'events.views.get_matches_from_round'),
url(r'^events/allevents/', 'events.views.get_events'),
url(r'^events/get_event/', 'events.views.get_event'),
+ url(r'^users/getallfavs/', 'users.views.get_favorites'),
)
View
8 users/models.py
@@ -13,9 +13,17 @@ class UserProfile(models.Model):
def __unicode__(self):
return self.user.username
+
+ def favorites_to_dict(self):
+ return {
+ 'favorite_players':[player.pk for player in self.favorite_players.all()],
+ 'favorite_teams':[team.pk for team in self.favorite_teams.all()],
+ 'favorite_events':[event.pk for event in self.favorite_events.all()]
+ }
def create_user_profile(sender, instance, created, **kwargs):
if created:
UserProfile.objects.create(user = instance)
+
post_save.connect(create_user_profile, sender=User)
View
10 users/views.py
@@ -209,6 +209,16 @@ def remove_favorite_event(request):
response["response"] = "Remove favorite event successful!"
return HttpResponse(simplejson.dumps(response), mimetype="application/json")
+def get_favorites(request):
+ user = is_auth(request)
+ response = {}
+ if user is None:
+ return auth_required_response()
+ profile = user.get_profile()
+ response['status_code'] = 200
+ response['response'] = profile.favorites_to_dict()
+ return HttpResponse(simplejson.dumps(response), mimetype='application/json')
+
create_user = csrf_exempt(create_user)
authenticate_user = csrf_exempt(authenticate_user)

0 comments on commit 70f1389

Please sign in to comment.
Something went wrong with that request. Please try again.