本文整理汇总了Python中openedx.core.djangoapps.user_api.models.UserPreference.get_value方法的典型用法代码示例。如果您正苦于以下问题:Python UserPreference.get_value方法的具体用法?Python UserPreference.get_value怎么用?Python UserPreference.get_value使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类openedx.core.djangoapps.user_api.models.UserPreference
的用法示例。
在下文中一共展示了UserPreference.get_value方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_custom_visibility_over_age
# 需要导入模块: from openedx.core.djangoapps.user_api.models import UserPreference [as 别名]
# 或者: from openedx.core.djangoapps.user_api.models.UserPreference import get_value [as 别名]
def test_custom_visibility_over_age(self, api_client, requesting_username):
self.create_mock_profile(self.user)
# set user's custom visibility preferences
set_user_preference(self.user, ACCOUNT_VISIBILITY_PREF_KEY, CUSTOM_VISIBILITY)
shared_fields = ("bio", "language_proficiencies", "name")
for field_name in shared_fields:
set_user_preference(self.user, "visibility.{}".format(field_name), ALL_USERS_VISIBILITY)
# make API request
client = self.login_client(api_client, requesting_username)
response = self.send_get(client)
# verify response
if requesting_username == "different_user":
data = response.data
self.assertEqual(6, len(data))
# public fields
self.assertEqual(self.user.username, data["username"])
self.assertEqual(UserPreference.get_value(self.user, 'account_privacy'), data["account_privacy"])
self._verify_profile_image_data(data, has_profile_image=True)
# custom shared fields
self.assertEqual(TEST_BIO_VALUE, data["bio"])
self.assertEqual([{"code": TEST_LANGUAGE_PROFICIENCY_CODE}], data["language_proficiencies"])
self.assertEqual(self.user.first_name + " " + self.user.last_name, data["name"])
else:
self._verify_full_account_response(response)
示例2: get_user_email_language
# 需要导入模块: from openedx.core.djangoapps.user_api.models import UserPreference [as 别名]
# 或者: from openedx.core.djangoapps.user_api.models.UserPreference import get_value [as 别名]
def get_user_email_language(user):
"""
Return the language most appropriate for writing emails to user. Returns
None if the preference has not been set, or if the user does not exist.
"""
# Calling UserPreference directly instead of get_user_preference because the user requesting the
# information is not "user" and also may not have is_staff access.
return UserPreference.get_value(user, LANGUAGE_KEY)
示例3: get_profile_visibility
# 需要导入模块: from openedx.core.djangoapps.user_api.models import UserPreference [as 别名]
# 或者: from openedx.core.djangoapps.user_api.models.UserPreference import get_value [as 别名]
def get_profile_visibility(user_profile, user, configuration=None):
"""Returns the visibility level for the specified user profile."""
if user_profile.requires_parental_consent():
return PRIVATE_VISIBILITY
if not configuration:
configuration = settings.ACCOUNT_VISIBILITY_CONFIGURATION
# Calling UserPreference directly because the requesting user may be different from existing_user
# (and does not have to be is_staff).
profile_privacy = UserPreference.get_value(user, ACCOUNT_VISIBILITY_PREF_KEY)
return profile_privacy if profile_privacy else configuration.get('default_visibility')
示例4: share_with_facebook_friends
# 需要导入模块: from openedx.core.djangoapps.user_api.models import UserPreference [as 别名]
# 或者: from openedx.core.djangoapps.user_api.models.UserPreference import get_value [as 别名]
def share_with_facebook_friends(friend):
"""
Return true if the user's share_with_facebook_friends preference is set to true.
"""
# Calling UserPreference directly because the requesting user may be different (and not is_staff).
try:
existing_user = User.objects.get(username=friend['edX_username'])
except ObjectDoesNotExist:
return False
return UserPreference.get_value(existing_user, 'share_with_facebook_friends') == 'True'
示例5: claim_locale
# 需要导入模块: from openedx.core.djangoapps.user_api.models import UserPreference [as 别名]
# 或者: from openedx.core.djangoapps.user_api.models.UserPreference import get_value [as 别名]
def claim_locale(self, data):
"""
Return the locale for the users based on their preferences.
Does not return a value if the users have not set their locale preferences.
"""
# Calling UserPreference directly because it is not clear which user made the request.
language = UserPreference.get_value(data['user'], LANGUAGE_KEY)
# If the user has no language specified, return the default one.
if not language:
language = settings.LANGUAGE_CODE
return language
示例6: _verify_full_account_response
# 需要导入模块: from openedx.core.djangoapps.user_api.models import UserPreference [as 别名]
# 或者: from openedx.core.djangoapps.user_api.models.UserPreference import get_value [as 别名]
def _verify_full_account_response(self, response, requires_parental_consent=False, year_of_birth=2000):
"""
Verify that all account fields are returned (even those that are not shareable).
"""
data = response.data
self.assertEqual(22, len(data))
# public fields (3)
expected_account_privacy = (
PRIVATE_VISIBILITY if requires_parental_consent else
UserPreference.get_value(self.user, 'account_privacy')
)
self.assertEqual(expected_account_privacy, data["account_privacy"])
self._verify_profile_image_data(data, not requires_parental_consent)
self.assertEqual(self.user.username, data["username"])
# additional shareable fields (8)
self.assertEqual(TEST_BIO_VALUE, data["bio"])
self.assertEqual("US", data["country"])
self.assertIsNotNone(data["date_joined"])
self.assertEqual([{"code": TEST_LANGUAGE_PROFICIENCY_CODE}], data["language_proficiencies"])
self.assertEqual("m", data["level_of_education"])
self.assertIsNotNone(data["social_links"])
self.assertEqual(UserPreference.get_value(self.user, 'time_zone'), data["time_zone"])
self.assertIsNotNone(data["accomplishments_shared"])
self.assertEqual(self.user.first_name + " " + self.user.last_name, data["name"])
# additional admin fields (10)
self.assertEqual(self.user.email, data["email"])
self.assertIsNotNone(data["extended_profile"])
self.assertEqual("f", data["gender"])
self.assertEqual("world peace", data["goals"])
self.assertTrue(data["is_active"])
self.assertEqual("Park Ave", data['mailing_address'])
self.assertEquals(requires_parental_consent, data["requires_parental_consent"])
self.assertIsNone(data["secondary_email"])
self.assertEqual(year_of_birth, data["year_of_birth"])
示例7: render_to_fragment
# 需要导入模块: from openedx.core.djangoapps.user_api.models import UserPreference [as 别名]
# 或者: from openedx.core.djangoapps.user_api.models.UserPreference import get_value [as 别名]
def render_to_fragment(self, request, course_id=None, **kwargs):
"""
Renders the user's course bookmarks as a fragment.
"""
course_key = CourseKey.from_string(course_id)
course = get_course_with_access(request.user, 'load', course_key, check_if_enrolled=True)
language = UserPreference.get_value(request.user, 'pref-lang', default='en')
context = {
'csrf': csrf(request)['csrf_token'],
'course': course,
'bookmarks_api_url': reverse('bookmarks'),
'language_preference': language,
}
html = render_to_string('course_bookmarks/course-bookmarks-fragment.html', context)
inline_js = render_to_string('course_bookmarks/course_bookmarks_js.template', context)
fragment = Fragment(html)
self.add_fragment_resource_urls(fragment)
fragment.add_javascript(inline_js)
return fragment
示例8: _verify_full_account_response
# 需要导入模块: from openedx.core.djangoapps.user_api.models import UserPreference [as 别名]
# 或者: from openedx.core.djangoapps.user_api.models.UserPreference import get_value [as 别名]
def _verify_full_account_response(self, response, requires_parental_consent=False):
"""
Verify that all account fields are returned (even those that are not shareable).
"""
data = response.data
self.assertEqual(17, len(data))
self.assertEqual(self.user.username, data["username"])
self.assertEqual(self.user.first_name + " " + self.user.last_name, data["name"])
self.assertEqual("US", data["country"])
self.assertEqual("f", data["gender"])
self.assertEqual(2000, data["year_of_birth"])
self.assertEqual("m", data["level_of_education"])
self.assertEqual("world peace", data["goals"])
self.assertEqual("Park Ave", data['mailing_address'])
self.assertEqual(self.user.email, data["email"])
self.assertTrue(data["is_active"])
self.assertIsNotNone(data["date_joined"])
self.assertEqual("Tired mother of twins", data["bio"])
self._verify_profile_image_data(data, not requires_parental_consent)
self.assertEquals(requires_parental_consent, data["requires_parental_consent"])
self.assertEqual([{"code": "en"}], data["language_proficiencies"])
self.assertEqual(UserPreference.get_value(self.user, 'account_privacy'), data["account_privacy"])