当前位置: 首页>>代码示例>>Python>>正文


Python models.UserProfile类代码示例

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


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


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