本文整理汇总了Python中mozillians.users.models.UserProfile.search方法的典型用法代码示例。如果您正苦于以下问题:Python UserProfile.search方法的具体用法?Python UserProfile.search怎么用?Python UserProfile.search使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mozillians.users.models.UserProfile
的用法示例。
在下文中一共展示了UserProfile.search方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_search_no_public_with_unvouched
# 需要导入模块: from mozillians.users.models import UserProfile [as 别名]
# 或者: from mozillians.users.models.UserProfile import search [as 别名]
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: test_search_no_public_only_vouched
# 需要导入模块: from mozillians.users.models import UserProfile [as 别名]
# 或者: from mozillians.users.models.UserProfile import search [as 别名]
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: search
# 需要导入模块: from mozillians.users.models import UserProfile [as 别名]
# 或者: from mozillians.users.models.UserProfile import search [as 别名]
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)
示例4: betasearch
# 需要导入模块: from mozillians.users.models import UserProfile [as 别名]
# 或者: from mozillians.users.models.UserProfile import search [as 别名]
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)
示例5: test_search_public_only_vouched
# 需要导入模块: from mozillians.users.models import UserProfile [as 别名]
# 或者: from mozillians.users.models.UserProfile import search [as 别名]
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)
)
示例6: search
# 需要导入模块: from mozillians.users.models import UserProfile [as 别名]
# 或者: from mozillians.users.models.UserProfile import search [as 别名]
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)
示例7: betasearch
# 需要导入模块: from mozillians.users.models import UserProfile [as 别名]
# 或者: from mozillians.users.models.UserProfile import search [as 别名]
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)
示例8: test_empty_query_search
# 需要导入模块: from mozillians.users.models import UserProfile [as 别名]
# 或者: from mozillians.users.models.UserProfile import search [as 别名]
def test_empty_query_search(self):
"""Make sure the search method works with an empty query."""
assert UserProfile.search('').count()