• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python models.UserProfile类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中mozillians.users.models.UserProfile的典型用法代码示例。如果您正苦于以下问题:Python UserProfile类的具体用法?Python UserProfile怎么用?Python UserProfile使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了UserProfile类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: test_lookup_token_unregistered

 def test_lookup_token_unregistered(self, mock_lookup_user):
     # Lookup token for a user with no registered email
     # Basket raises unknown user exception, then lookup-token returns None
     user = User(email="[email protected]")
     profile = UserProfile(user=user)
     mock_lookup_user.side_effect = basket.BasketException(code=basket.errors.BASKET_UNKNOWN_EMAIL)
     result = profile.lookup_basket_token()
     ok_(result is None)
开发者ID:J0WI,项目名称:mozillians,代码行数:8,代码来源:test_models.py


示例2: test_lookup_token_registered

 def test_lookup_token_registered(self, mock_lookup_user):
     # Lookup token for a user with registered email
     # basket returns response with data, lookup_basket_token returns the token
     user = User(email='[email protected]')
     profile = UserProfile(user=user)
     mock_lookup_user.return_value = {'status': 'ok', 'token': 'FAKETOKEN'}
     result = profile.lookup_basket_token()
     eq_('FAKETOKEN', result)
开发者ID:royshouvik,项目名称:mozillians,代码行数:8,代码来源:test_models.py


示例3: test_set_privacy_level_without_save

 def test_set_privacy_level_without_save(self):
     user = UserFactory.create()
     user.userprofile.set_privacy_level(9, save=False)
     for field in UserProfile.privacy_fields():
         eq_(getattr(user.userprofile, "privacy_{0}".format(field)), 9, "Field {0} not set".format(field))
     user = User.objects.get(id=user.id)
     for field in UserProfile.privacy_fields():
         # Compare to default privacy setting for each field.
         f = UserProfile._meta.get_field_by_name("privacy_{0}".format(field))[0]
         eq_(getattr(user.userprofile, "privacy_{0}".format(field)), f.default, "Field {0} not set".format(field))
开发者ID:J0WI,项目名称:mozillians,代码行数:10,代码来源:test_models.py


示例4: test_lookup_token_exceptions

 def test_lookup_token_exceptions(self, mock_lookup_user):
     # If basket raises any exception other than BASKET_UNKNOWN_EMAIL when
     # we call lookup_basket_token, lookup_basket_token passes it up the chain
     class SomeException(Exception):
         pass
     user = User(email='[email protected]')
     profile = UserProfile(user=user)
     mock_lookup_user.side_effect = SomeException
     with self.assertRaises(SomeException):
         profile.lookup_basket_token()
开发者ID:royshouvik,项目名称:mozillians,代码行数:10,代码来源:test_models.py


示例5: test_caching

 def test_caching(self):
     # It would be better if this test didn't need to know how the
     # caching worked.
     # To compute the privacy fields, the code has to get all the
     # field names. Use mock so we can tell if that gets called.
     with patch.object(UserProfile._meta, 'get_all_field_names') as mock_get_all_field_names:
         UserProfile.privacy_fields()
     ok_(mock_get_all_field_names.called)
     # If we call privacy_fields() again, it shouldn't need to compute it all again
     with patch.object(UserProfile._meta, 'get_all_field_names') as mock_get_all_field_names:
         UserProfile.privacy_fields()
     ok_(not mock_get_all_field_names.called)
开发者ID:royshouvik,项目名称:mozillians,代码行数:12,代码来源:test_models.py


示例6: test_profile_model

 def test_profile_model(self):
     fields = UserProfile.privacy_fields()
     eq_("", fields["ircname"])
     eq_("", fields["email"])
     ok_("is_vouched" not in fields)
     ok_("date_vouched" not in fields)
     ok_(fields["tshirt"] is None)
开发者ID:J0WI,项目名称:mozillians,代码行数:7,代码来源:test_models.py


示例7: test_set_privacy_level_with_save

 def test_set_privacy_level_with_save(self):
     user = UserFactory.create()
     user.userprofile.set_privacy_level(9)
     user = User.objects.get(id=user.id)
     for field in UserProfile.privacy_fields():
         eq_(getattr(user.userprofile, 'privacy_{0}'.format(field)), 9,
             'Field {0} not set'.format(field))
开发者ID:royshouvik,项目名称:mozillians,代码行数:7,代码来源:test_models.py


示例8: test_search_no_public_with_unvouched

 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)
开发者ID:J0WI,项目名称:mozillians,代码行数:7,代码来源:test_models.py


示例9: test_removal_from_public_index

    def test_removal_from_public_index(self):
        """Test that a user gets removed from public index if makes
        profile mozillians only again.

        """
        before = (S(UserProfile)
                  .indexes(UserProfile.get_index(public_index=True))
                  .count())
        profile = self.mozillian2.userprofile
        profile.privacy_full_name = MOZILLIANS
        profile.save()
        sleep(1)
        after = (S(UserProfile)
                 .indexes(UserProfile.get_index(public_index=True))
                 .count())
        eq_(after+1, before)
开发者ID:erinversfeld,项目名称:mozillians-new,代码行数:16,代码来源:test_search.py


示例10: test_extract_document

    def test_extract_document(self):
        user = UserFactory.create(userprofile={'allows_community_sites': False,
                                               'allows_mozilla_sites': False,
                                               'full_name': 'Nikos Koukos',
                                               'bio': 'This is my bio'})
        profile = user.userprofile
        group_1 = GroupFactory.create()
        group_2 = GroupFactory.create()
        skill_1 = SkillFactory.create()
        skill_2 = SkillFactory.create()
        LanguageFactory.create(code='fr', userprofile=profile)
        LanguageFactory.create(code='en', userprofile=profile)
        group_1.add_member(profile)
        group_2.add_member(profile)
        profile.skills.add(skill_1)
        profile.skills.add(skill_2)

        result = UserProfile.extract_document(profile.id)
        ok_(isinstance(result, dict))
        eq_(result['id'], profile.id)
        eq_(result['is_vouched'], profile.is_vouched)
        eq_(result['region'], 'Attika')
        eq_(result['city'], 'Athens')
        eq_(result['allows_community_sites'], profile.allows_community_sites)
        eq_(result['allows_mozilla_sites'], profile.allows_mozilla_sites)
        eq_(set(result['country']), set(['gr', 'Greece']))
        eq_(result['fullname'], profile.full_name.lower())
        eq_(result['name'], profile.full_name.lower())
        eq_(result['bio'], profile.bio)
        eq_(result['has_photo'], False)
        eq_(result['groups'], [group_1.name, group_2.name])
        eq_(result['skills'], [skill_1.name, skill_2.name])
        eq_(set(result['languages']),
            set([u'en', u'fr', u'english', u'french', u'français']))
开发者ID:WillsMcGarnigle,项目名称:mozillians,代码行数:34,代码来源:test_models.py


示例11: test_profile_model

 def test_profile_model(self):
     fields = UserProfile.privacy_fields()
     eq_('', fields['ircname'])
     eq_('', fields['email'])
     ok_('is_vouched' not in fields)
     ok_('date_vouched' not in fields)
     ok_(fields['tshirt'] is None)
开发者ID:royshouvik,项目名称:mozillians,代码行数:7,代码来源:test_models.py


示例12: test_search_no_public_only_vouched

 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)
开发者ID:TheGallery,项目名称:mozillians,代码行数:8,代码来源:test_models.py


示例13: search

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)
开发者ID:SudeepSrinivas,项目名称:mozillians,代码行数:51,代码来源:views.py


示例14: betasearch

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)
开发者ID:maheshkkumar,项目名称:mozillians,代码行数:49,代码来源:views.py


示例15: test_search_public_only_vouched

 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)
     )
开发者ID:J0WI,项目名称:mozillians,代码行数:15,代码来源:test_models.py


示例16: search

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)
开发者ID:rahulrrixe,项目名称:mozillians,代码行数:47,代码来源:views.py


示例17: betasearch

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)
开发者ID:KryDos,项目名称:mozillians,代码行数:47,代码来源:views.py


示例18: test_extract_document

    def test_extract_document(self):
        country = CountryFactory.create(name="Greece", code="gr")
        region = RegionFactory.create(name="attika", country=country)
        city = CityFactory.create(name="athens", region=region, country=country)
        user = UserFactory.create(
            userprofile={
                "geo_city": city,
                "geo_region": region,
                "allows_community_sites": False,
                "allows_mozilla_sites": False,
                "geo_country": country,
                "full_name": "Nikos Koukos",
                "bio": "This is my bio",
            }
        )
        profile = user.userprofile
        group_1 = GroupFactory.create()
        group_2 = GroupFactory.create()
        skill_1 = SkillFactory.create()
        skill_2 = SkillFactory.create()
        LanguageFactory.create(code="fr", userprofile=profile)
        LanguageFactory.create(code="en", userprofile=profile)
        group_1.add_member(profile)
        group_2.add_member(profile)
        profile.skills.add(skill_1)
        profile.skills.add(skill_2)

        result = UserProfile.extract_document(user.userprofile.id)
        ok_(isinstance(result, dict))
        eq_(result["id"], profile.id)
        eq_(result["is_vouched"], profile.is_vouched)
        eq_(result["region"], region.name)
        eq_(result["city"], city.name)
        eq_(result["allows_community_sites"], profile.allows_community_sites)
        eq_(result["allows_mozilla_sites"], profile.allows_mozilla_sites)
        eq_(result["country"], country.name)
        eq_(result["fullname"], profile.full_name.lower())
        eq_(result["name"], profile.full_name.lower())
        eq_(result["bio"], profile.bio)
        eq_(result["has_photo"], False)
        eq_(result["groups"], [group_1.name, group_2.name])
        eq_(result["skills"], [skill_1.name, skill_2.name])
        eq_(set(result["languages"]), set([u"en", u"fr", u"english", u"french", u"français"]))
开发者ID:J0WI,项目名称:mozillians,代码行数:43,代码来源:test_models.py


示例19: test_extract_document

    def test_extract_document(self):
        group_1 = GroupFactory.create()
        group_2 = GroupFactory.create()
        skill_1 = SkillFactory.create()
        skill_2 = SkillFactory.create()
        language_1 = LanguageFactory.create()
        language_2 = LanguageFactory.create()
        user = UserFactory.create(userprofile={'website': 'bestplaceonthenet.com',
                                               'city': 'athens',
                                               'region': 'attika',
                                               'allows_community_sites': False,
                                               'allows_mozilla_sites': False,
                                               'country': 'gr',
                                               'full_name': 'Nikos Koukos',
                                               'bio': 'This is my bio'})
        profile = user.userprofile
        profile.groups.add(group_1)
        profile.groups.add(group_2)
        profile.skills.add(skill_1)
        profile.skills.add(skill_2)
        profile.languages.add(language_1)
        profile.languages.add(language_2)

        result = UserProfile.extract_document(user.userprofile.id)
        ok_(isinstance(result, dict))
        eq_(result['id'], profile.id)
        eq_(result['is_vouched'], profile.is_vouched)
        eq_(result['website'], profile.website)
        eq_(result['region'], profile.region)
        eq_(result['city'], profile.city)
        eq_(result['allows_community_sites'], profile.allows_community_sites)
        eq_(result['allows_mozilla_sites'], profile.allows_mozilla_sites)
        eq_(result['country'], ['gr', 'greece'])
        eq_(result['fullname'], profile.full_name.lower())
        eq_(result['name'], profile.full_name.lower())
        eq_(result['bio'], profile.bio)
        eq_(result['has_photo'], False)
        eq_(result['groups'], [group_1.name, group_2.name])
        eq_(result['skills'], [skill_1.name, skill_2.name])
        eq_(result['languages'], [language_1.name, language_2.name])
开发者ID:TheGallery,项目名称:mozillians,代码行数:40,代码来源:test_models.py


示例20: index_all_profiles

def index_all_profiles():
    # Get an es object, delete index and re-create it
    es = get_es(timeout=settings.ES_INDEXING_TIMEOUT)
    mappings = {"mappings": {UserProfile._meta.db_table: UserProfile.get_mapping()}}

    def _recreate_index(index):
        try:
            es.delete_index_if_exists(index)
        except pyes.exceptions.IndexMissingException:
            pass
        es.create_index(index, settings=mappings)

    _recreate_index(settings.ES_INDEXES["default"])
    _recreate_index(settings.ES_INDEXES["public"])

    # mozillians index
    ids = UserProfile.objects.complete().values_list("id", flat=True)
    ts = [index_objects.subtask(args=[UserProfile, chunk, False]) for chunk in chunked(sorted(list(ids)), 150)]

    # public index
    ids = UserProfile.objects.complete().public_indexable().privacy_level(PUBLIC).values_list("id", flat=True)
    ts += [index_objects.subtask(args=[UserProfile, chunk, True]) for chunk in chunked(sorted(list(ids)), 150)]

    TaskSet(ts).apply_async()
开发者ID:J0WI,项目名称:mozillians,代码行数:24,代码来源:cron.py



注:本文中的mozillians.users.models.UserProfile类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python unindex_objects.delay函数代码示例发布时间:2022-05-27
下一篇:
Python tests.InviteFactory类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap