本文整理汇总了Python中openedx.core.djangoapps.user_api.models.UserPreference.get_preference方法的典型用法代码示例。如果您正苦于以下问题:Python UserPreference.get_preference方法的具体用法?Python UserPreference.get_preference怎么用?Python UserPreference.get_preference使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类openedx.core.djangoapps.user_api.models.UserPreference
的用法示例。
在下文中一共展示了UserPreference.get_preference方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_set_preference_missing_lang
# 需要导入模块: from openedx.core.djangoapps.user_api.models import UserPreference [as 别名]
# 或者: from openedx.core.djangoapps.user_api.models.UserPreference import get_preference [as 别名]
def test_set_preference_missing_lang(self):
user = UserFactory.create()
self.client.login(username=user.username, password='test')
response = self.client.post(reverse('lang_pref_set_language'))
self.assertEquals(response.status_code, 400)
self.assertIsNone(UserPreference.get_preference(user, LANGUAGE_KEY))
示例2: process_request
# 需要导入模块: from openedx.core.djangoapps.user_api.models import UserPreference [as 别名]
# 或者: from openedx.core.djangoapps.user_api.models.UserPreference import get_preference [as 别名]
def process_request(self, request):
"""
If a user's UserPreference contains a language preference and there is
no language set on the session (i.e. from dark language overrides), use the user's preference.
"""
if request.user.is_authenticated() and 'django_language' not in request.session:
user_pref = UserPreference.get_preference(request.user, LANGUAGE_KEY)
if user_pref:
request.session['django_language'] = user_pref
示例3: test_discussions_email_digest_pref
# 需要导入模块: from openedx.core.djangoapps.user_api.models import UserPreference [as 别名]
# 或者: from openedx.core.djangoapps.user_api.models.UserPreference import get_preference [as 别名]
def test_discussions_email_digest_pref(self, digest_enabled):
with mock.patch.dict("student.models.settings.FEATURES", {"ENABLE_DISCUSSION_EMAIL_DIGEST": digest_enabled}):
response = self.client.post(self.url, self.params)
self.assertEqual(response.status_code, 200)
user = User.objects.get(username=self.username)
preference = UserPreference.get_preference(user, NOTIFICATION_PREF_KEY)
if digest_enabled:
self.assertIsNotNone(preference)
else:
self.assertIsNone(preference)
示例4: test_set_preference_happy
# 需要导入模块: from openedx.core.djangoapps.user_api.models import UserPreference [as 别名]
# 或者: from openedx.core.djangoapps.user_api.models.UserPreference import get_preference [as 别名]
def test_set_preference_happy(self):
user = UserFactory.create()
self.client.login(username=user.username, password='test')
lang = 'en'
response = self.client.post(reverse('lang_pref_set_language'), {'language': lang})
self.assertEquals(response.status_code, 200)
user_pref = UserPreference.get_preference(user, LANGUAGE_KEY)
self.assertEqual(user_pref, lang)
示例5: claim_locale
# 需要导入模块: from openedx.core.djangoapps.user_api.models import UserPreference [as 别名]
# 或者: from openedx.core.djangoapps.user_api.models.UserPreference import get_preference [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.
"""
language = UserPreference.get_preference(data['user'], LANGUAGE_KEY)
# If the user has no language specified, return the default one.
if not language:
language = getattr(settings, 'LANGUAGE_CODE')
return language
示例6: get_user_email_language
# 需要导入模块: from openedx.core.djangoapps.user_api.models import UserPreference [as 别名]
# 或者: from openedx.core.djangoapps.user_api.models.UserPreference import get_preference [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.
"""
return UserPreference.get_preference(user, LANGUAGE_KEY)
示例7: test_header_lang_pref_saved
# 需要导入模块: from openedx.core.djangoapps.user_api.models import UserPreference [as 别名]
# 或者: from openedx.core.djangoapps.user_api.models.UserPreference import get_preference [as 别名]
def test_header_lang_pref_saved(self, lang):
response = self.client.post(self.url, self.params, HTTP_ACCEPT_LANGUAGE=lang)
user = User.objects.get(username=self.username)
self.assertEqual(response.status_code, 200)
self.assertEqual(UserPreference.get_preference(user, LANGUAGE_KEY), lang)
示例8: test_default_lang_pref_saved
# 需要导入模块: from openedx.core.djangoapps.user_api.models import UserPreference [as 别名]
# 或者: from openedx.core.djangoapps.user_api.models.UserPreference import get_preference [as 别名]
def test_default_lang_pref_saved(self, lang):
with mock.patch("django.conf.settings.LANGUAGE_CODE", lang):
response = self.client.post(self.url, self.params)
self.assertEqual(response.status_code, 200)
user = User.objects.get(username=self.username)
self.assertEqual(UserPreference.get_preference(user, LANGUAGE_KEY), lang)