Skip to content
This repository has been archived by the owner on Jan 19, 2021. It is now read-only.

Commit

Permalink
Merge pull request #975 from Sancus/1026258-location-list
Browse files Browse the repository at this point in the history
[Fix Bug 1025160] Location list pages should only display profiles that match all arguments.
  • Loading branch information
Sancus committed Jun 19, 2014
2 parents dd3536d + 6369c2b commit 8593d10
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
6 changes: 6 additions & 0 deletions mozillians/phonebook/tests/test_views/test_views_list.py
Expand Up @@ -148,6 +148,10 @@ def test_list_mozillians_in_location_city_vouched(self):
eq_(response.context['people'].object_list[0], user_listed.userprofile)

def test_list_mozillians_in_location_region_n_city_vouched(self):
"""
Test that only vouched users with the correct country, city
and region show up in the list view.
"""
country = CountryFactory.create()
country2 = CountryFactory.create()
region = RegionFactory.create(country=country)
Expand All @@ -164,6 +168,8 @@ def test_list_mozillians_in_location_region_n_city_vouched(self):
UserFactory.create()
UserFactory.create(vouched=False)
UserFactory.create(vouched=False, userprofile={'geo_country': country2})
UserFactory.create(userprofile={'geo_country': country})
UserFactory.create(userprofile={'geo_country': country, 'geo_region': region})
user = UserFactory.create()
with self.login(user) as client:
url = reverse('phonebook:list_region_city',
Expand Down
7 changes: 2 additions & 5 deletions mozillians/phonebook/views.py
Expand Up @@ -4,7 +4,6 @@
from django.contrib.auth.decorators import login_required
from django.contrib.auth.models import User
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
from django.db.models import Q
from django.http import Http404, HttpResponseBadRequest
from django.shortcuts import get_object_or_404, render
from django.views.decorators.cache import cache_page, never_cache
Expand Down Expand Up @@ -342,11 +341,9 @@ def list_mozillians_in_location(request, country, region=None, city=None):
show_pagination = False

if city:
# Don't exclude people who haven't entered a city, they might be in the
# desired city.
queryset = queryset.filter(Q(geo_city__name__iexact=city) | Q(geo_city=None))
queryset = queryset.filter(geo_city__name__iexact=city)
if region:
queryset = queryset.filter(Q(geo_region__name__iexact=region) | Q(geo_region=None))
queryset = queryset.filter(geo_region__name__iexact=region)

paginator = Paginator(queryset, settings.ITEMS_PER_PAGE)
page = request.GET.get('page', 1)
Expand Down

0 comments on commit 8593d10

Please sign in to comment.