Permalink
Browse files

Make use of values_list with flat kwarg instead of using list compreh…

…ensions.
  • Loading branch information...
ericflo committed Oct 4, 2008
1 parent d55e176 commit ce8b1d7a4954d9f5f7137d9b2c5a16c2474691f2
Showing with 15 additions and 13 deletions.
  1. +4 −4 events/views.py
  2. +11 −9 socialgraph/util.py
View
@@ -30,8 +30,8 @@ def tonight(request, everyone=True):
attendance__user=request.user)
events = events.exclude(creator=request.user).exclude(
attendance__user=request.user)
- following = [i['to_user'] for i in
- request.user.following_set.all().values('to_user')]
+ following = request.user.following_set.all().values_list('to_user',
+ flat=True)
else:
my_events = Event.objects.none()
following = None
@@ -64,8 +64,8 @@ def archive(request, everyone=True):
events = Event.objects.filter(latest=True) | Event.objects.filter(
attendance__user__isnull=False)
if request.user.is_authenticated():
- following = [i['to_user'] for i in
- request.user.following_set.all().values('to_user')]
+ following = request.user.following_set.all().values_list('to_user',
+ flat=True)
else:
following = None
if not everyone:
View
@@ -5,23 +5,25 @@ def get_people_user_follows(user):
"""
Returns a ``QuerySet`` representing the users that the given user follows.
"""
- ul = UserLink.objects.filter(from_user=user).values('to_user')
- return User.objects.filter(id__in=[i['to_user'] for i in ul])
+ ul = UserLink.objects.filter(from_user=user).values_list('to_user',
+ flat=True)
+ return User.objects.filter(id__in=ul)
def get_people_following_user(user):
"""
Returns a ``QuerySet`` representing the users that follow the given user.
"""
- ul = UserLink.objects.filter(to_user=user).values('from_user')
- return User.objects.filter(id__in=[i['from_user'] for i in ul])
+ ul = UserLink.objects.filter(to_user=user).values_list('from_user',
+ flat=True)
+ return User.objects.filter(id__in=ul)
def get_mutual_followers(user):
"""
Returns a ``QuerySet`` representing the users that the given user follows,
who also follow the given user back.
"""
- follows = UserLink.objects.filter(from_user=user).values('to_user')
- following = UserLink.objects.filter(to_user=user).values('from_user')
- follows_set = set([i['to_user'] for i in follows])
- following_set = set([i['from_user'] for i in following])
- return User.objects.filter(id__in=follows_set.intersection(following_set))
+ follows = UserLink.objects.filter(from_user=user).values_list('to_user',
+ flat=True)
+ following = UserLink.objects.filter(to_user=user).values_list('from_user',
+ flat=True)
+ return User.objects.filter(id__in=set(follows).intersection(set(following)))

0 comments on commit ce8b1d7

Please sign in to comment.