示例#1
0
 def test_search_no_public_with_unvouched(self, PrivacyAwareSMock):
     result = UserProfile.search("foo", include_non_vouched=True)
     ok_(isinstance(result, Mock))
     PrivacyAwareSMock.assert_any_call(UserProfile)
     PrivacyAwareSMock().indexes.assert_any_call("index")
     ok_(call().indexes().boost().query().order_by().filter(is_vouched=True) not in PrivacyAwareSMock.mock_calls)
     ok_(call().privacy_level(PUBLIC) not in PrivacyAwareSMock.mock_calls)
示例#2
0
 def test_search_no_public_only_vouched(self, PrivacyAwareSMock):
     result = UserProfile.search('foo')
     ok_(isinstance(result, Mock))
     PrivacyAwareSMock.assert_any_call(UserProfile)
     PrivacyAwareSMock().indexes.assert_any_call('index')
     (PrivacyAwareSMock().indexes().boost()
      .query().order_by().filter.assert_any_call(is_vouched=True))
     ok_(call().privacy_level(PUBLIC) not in PrivacyAwareSMock.mock_calls)
示例#3
0
 def test_search_no_public_only_vouched(self, PrivacyAwareSMock):
     result = UserProfile.search('foo')
     ok_(isinstance(result, Mock))
     PrivacyAwareSMock.assert_any_call(UserProfile)
     PrivacyAwareSMock().indexes.assert_any_call('index')
     (PrivacyAwareSMock().indexes().boost()
      .query().order_by().filter.assert_any_call(is_vouched=True))
     ok_(call().privacy_level(PUBLIC) not in PrivacyAwareSMock.mock_calls)
示例#4
0
 def test_search_public_with_unvouched(self, PrivacyAwareSMock):
     result = UserProfile.search(
         'foo', public=True, include_non_vouched=True)
     ok_(isinstance(result, Mock))
     PrivacyAwareSMock.assert_any_call(UserProfile)
     PrivacyAwareSMock().privacy_level.assert_any_call(PUBLIC)
     (PrivacyAwareSMock().privacy_level()
      .indexes.assert_any_call('public_index'))
     ok_(call().privacy_level().indexes().boost()
         .query().order_by().filter(is_vouched=True)
         not in PrivacyAwareSMock.mock_calls)
示例#5
0
def search(request):
    num_pages = 0
    limit = None
    people = []
    show_pagination = False
    form = forms.SearchForm(request.GET)
    groups = None
    curated_groups = None

    if form.is_valid():
        query = form.cleaned_data.get('q', u'')
        limit = form.cleaned_data['limit']
        include_non_vouched = form.cleaned_data['include_non_vouched']
        page = request.GET.get('page', 1)
        curated_groups = Group.get_curated()
        public = not (request.user.is_authenticated()
                      and request.user.userprofile.is_vouched)

        profiles = UserProfile.search(query,
                                      public=public,
                                      include_non_vouched=include_non_vouched)
        if not public:
            groups = Group.search(query)

        paginator = Paginator(profiles, limit)

        try:
            people = paginator.page(page)
        except PageNotAnInteger:
            people = paginator.page(1)
        except EmptyPage:
            people = paginator.page(paginator.num_pages)

        if profiles.count() == 1 and not groups:
            return redirect('phonebook:profile_view', people[0].user.username)

        if paginator.count > forms.PAGINATION_LIMIT:
            show_pagination = True
            num_pages = len(people.paginator.page_range)

    d = dict(people=people,
             form=form,
             limit=limit,
             show_pagination=show_pagination,
             num_pages=num_pages,
             groups=groups,
             curated_groups=curated_groups)

    if request.is_ajax():
        return render(request, 'search_ajax.html', d)

    return render(request, 'phonebook/search.html', d)
示例#6
0
def search(request):
    num_pages = 0
    limit = None
    people = []
    show_pagination = False
    form = forms.SearchForm(request.GET)
    groups = None
    curated_groups = None

    if form.is_valid():
        query = form.cleaned_data.get('q', u'')
        limit = form.cleaned_data['limit']
        include_non_vouched = form.cleaned_data['include_non_vouched']
        page = request.GET.get('page', 1)
        curated_groups = Group.get_curated()
        public = not (request.user.is_authenticated()
                      and request.user.userprofile.is_vouched)

        profiles = UserProfile.search(query, public=public,
                                      include_non_vouched=include_non_vouched)
        if not public:
            groups = Group.search(query)

        paginator = Paginator(profiles, limit)

        try:
            people = paginator.page(page)
        except PageNotAnInteger:
            people = paginator.page(1)
        except EmptyPage:
            people = paginator.page(paginator.num_pages)

        if profiles.count() == 1 and not groups:
            return redirect('phonebook:profile_view', people[0].user.username)

        if paginator.count > forms.PAGINATION_LIMIT:
            show_pagination = True
            num_pages = len(people.paginator.page_range)

    d = dict(people=people,
             search_form=form,
             limit=limit,
             show_pagination=show_pagination,
             num_pages=num_pages,
             groups=groups,
             curated_groups=curated_groups)

    if request.is_ajax():
        return render(request, 'search_ajax.html', d)

    return render(request, 'phonebook/search.html', d)
示例#7
0
def betasearch(request):
    """This view is for researching new search and data filtering
    options. It will eventually replace the 'search' view.

    This view is behind the 'betasearch' waffle flag.
    """
    limit = None
    people = []
    show_pagination = False
    form = forms.SearchForm(request.GET)
    groups = None
    functional_areas = None

    if form.is_valid():
        query = form.cleaned_data.get('q', u'')
        limit = form.cleaned_data['limit']
        include_non_vouched = form.cleaned_data['include_non_vouched']
        page = request.GET.get('page', 1)
        functional_areas = Group.get_functional_areas()
        public = not (request.user.is_authenticated()
                      and request.user.userprofile.is_vouched)

        profiles = UserProfile.search(query, public=public,
                                      include_non_vouched=include_non_vouched)
        if not public:
            groups = Group.search(query)

        paginator = Paginator(profiles, limit)

        try:
            people = paginator.page(page)
        except PageNotAnInteger:
            people = paginator.page(1)
        except EmptyPage:
            people = paginator.page(paginator.num_pages)

        if profiles.count() == 1 and not groups:
            return redirect('phonebook:profile_view', people[0].user.username)

        show_pagination = paginator.count > settings.ITEMS_PER_PAGE

    d = dict(people=people,
             search_form=form,
             limit=limit,
             show_pagination=show_pagination,
             groups=groups,
             functional_areas=functional_areas)

    return render(request, 'phonebook/betasearch.html', d)
示例#8
0
def betasearch(request):
    """This view is for researching new search and data filtering
    options. It will eventually replace the 'search' view.

    Filtering using SearchFilter does not respect privacy levels
    because it directly hits the db. This should be further
    investigated before the feature is released to the
    public. Meanwhile we limit searches only to vouched users.

    This view is behind the 'betasearch' waffle flag.

    """
    limit = None
    people = []
    show_pagination = False
    form = forms.SearchForm(request.GET)
    filtr = forms.SearchFilter(request.GET)

    if form.is_valid():
        query = form.cleaned_data.get('q', u'')
        limit = form.cleaned_data['limit']
        page = request.GET.get('page', 1)
        public = not (request.user.is_authenticated()
                      and request.user.userprofile.is_vouched)

        profiles_matching_filter = list(filtr.qs.values_list('id', flat=True))
        profiles = UserProfile.search(query,
                                      include_non_vouched=True,
                                      public=public)
        profiles = profiles.filter(id__in=profiles_matching_filter)

        paginator = Paginator(profiles, limit)

        try:
            people = paginator.page(page)
        except PageNotAnInteger:
            people = paginator.page(1)
        except EmptyPage:
            people = paginator.page(paginator.num_pages)

        show_pagination = paginator.count > settings.ITEMS_PER_PAGE

    data = dict(people=people,
                search_form=form,
                filtr=filtr,
                limit=limit,
                show_pagination=show_pagination)

    return render(request, 'phonebook/betasearch.html', data)
示例#9
0
 def test_search_public_only_vouched(self, PrivacyAwareSMock):
     result = UserProfile.search("foo", public=True)
     ok_(isinstance(result, Mock))
     PrivacyAwareSMock.assert_any_call(UserProfile)
     PrivacyAwareSMock().privacy_level.assert_any_call(PUBLIC)
     (PrivacyAwareSMock().privacy_level().indexes.assert_any_call("public_index"))
     (
         PrivacyAwareSMock()
         .privacy_level()
         .indexes()
         .boost()
         .query()
         .order_by()
         .filter.assert_any_call(is_vouched=True)
     )
示例#10
0
def search(request):
    limit = None
    people = []
    show_pagination = False
    form = forms.SearchForm(request.GET)
    groups = None
    curated_groups = None

    if form.is_valid():
        query = form.cleaned_data.get("q", u"")
        limit = form.cleaned_data["limit"]
        include_non_vouched = form.cleaned_data["include_non_vouched"]
        page = request.GET.get("page", 1)
        curated_groups = Group.get_curated()
        public = not (request.user.is_authenticated() and request.user.userprofile.is_vouched)

        profiles = UserProfile.search(query, public=public, include_non_vouched=include_non_vouched)
        if not public:
            groups = Group.search(query)

        paginator = Paginator(profiles, limit)

        try:
            people = paginator.page(page)
        except PageNotAnInteger:
            people = paginator.page(1)
        except EmptyPage:
            people = paginator.page(paginator.num_pages)

        if profiles.count() == 1 and not groups:
            return redirect("phonebook:profile_view", people[0].user.username)

        show_pagination = paginator.count > settings.ITEMS_PER_PAGE

    d = dict(
        people=people,
        search_form=form,
        limit=limit,
        show_pagination=show_pagination,
        groups=groups,
        curated_groups=curated_groups,
    )

    if request.is_ajax():
        return render(request, "search_ajax.html", d)

    return render(request, "phonebook/search.html", d)
示例#11
0
文件: views.py 项目: tinda/mozillians
def search(request):
    limit = None
    people = []
    show_pagination = False
    form = forms.SearchForm(request.GET)
    groups = None
    functional_areas = None

    if form.is_valid():
        query = form.cleaned_data.get('q', u'')
        limit = form.cleaned_data['limit']
        include_non_vouched = form.cleaned_data['include_non_vouched']
        page = request.GET.get('page', 1)
        functional_areas = Group.get_functional_areas()
        public = not (request.user.is_authenticated()
                      and request.user.userprofile.is_vouched)

        profiles = UserProfile.search(query, public=public,
                                      include_non_vouched=include_non_vouched)
        if not public:
            groups = Group.search(query)

        paginator = Paginator(profiles, limit)

        try:
            people = paginator.page(page)
        except PageNotAnInteger:
            people = paginator.page(1)
        except EmptyPage:
            people = paginator.page(paginator.num_pages)

        if profiles.count() == 1 and not groups:
            return redirect('phonebook:profile_view', people[0].user.username)

        show_pagination = paginator.count > settings.ITEMS_PER_PAGE

    d = dict(people=people,
             search_form=form,
             limit=limit,
             show_pagination=show_pagination,
             groups=groups,
             functional_areas=functional_areas)

    if request.is_ajax():
        return render(request, 'search_ajax.html', d)

    return render(request, 'phonebook/search.html', d)
示例#12
0
def betasearch(request):
    """This view is for researching new search and data filtering
    options. It will eventually replace the 'search' view.

    Filtering using SearchFilter does not respect privacy levels
    because it directly hits the db. This should be further
    investigated before the feature is released to the
    public. Meanwhile we limit searches only to vouched users.

    This view is behind the 'betasearch' waffle flag.

    """
    limit = None
    people = []
    show_pagination = False
    form = forms.SearchForm(request.GET)
    filtr = forms.SearchFilter(request.GET)

    if form.is_valid():
        query = form.cleaned_data.get('q', u'')
        limit = form.cleaned_data['limit']
        page = request.GET.get('page', 1)
        public = not (request.user.is_authenticated()
                      and request.user.userprofile.is_vouched)

        profiles_matching_filter = list(filtr.qs.values_list('id', flat=True))
        profiles = UserProfile.search(query, include_non_vouched=True, public=public)
        profiles = profiles.filter(id__in=profiles_matching_filter)

        paginator = Paginator(profiles, limit)

        try:
            people = paginator.page(page)
        except PageNotAnInteger:
            people = paginator.page(1)
        except EmptyPage:
            people = paginator.page(paginator.num_pages)

        show_pagination = paginator.count > settings.ITEMS_PER_PAGE

    data = dict(people=people,
                search_form=form,
                filtr=filtr,
                limit=limit,
                show_pagination=show_pagination)

    return render(request, 'phonebook/betasearch.html', data)
示例#13
0
 def test_empty_query_search(self):
     """Make sure the search method works with an empty query."""
     assert UserProfile.search('').count()