本文整理汇总了Python中openedx.core.djangoapps.user_api.models.UserPreference.set_preference方法的典型用法代码示例。如果您正苦于以下问题:Python UserPreference.set_preference方法的具体用法?Python UserPreference.set_preference怎么用?Python UserPreference.set_preference使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类openedx.core.djangoapps.user_api.models.UserPreference
的用法示例。
在下文中一共展示了UserPreference.set_preference方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_language_in_session
# 需要导入模块: from openedx.core.djangoapps.user_api.models import UserPreference [as 别名]
# 或者: from openedx.core.djangoapps.user_api.models.UserPreference import set_preference [as 别名]
def test_language_in_session(self):
# language set in both the user preferences and session,
# session should get precedence
self.request.session['django_language'] = 'en'
UserPreference.set_preference(self.user, LANGUAGE_KEY, 'eo')
self.middleware.process_request(self.request)
self.assertEquals(self.request.session['django_language'], 'en')
示例2: test_user_with_locale_claim
# 需要导入模块: from openedx.core.djangoapps.user_api.models import UserPreference [as 别名]
# 或者: from openedx.core.djangoapps.user_api.models.UserPreference import set_preference [as 别名]
def test_user_with_locale_claim(self):
language = "en"
UserPreference.set_preference(self.user, LANGUAGE_KEY, language)
scopes, claims = self.get_id_token_values("openid profile")
self.assertIn("profile", scopes)
locale = claims["locale"]
self.assertEqual(language, locale)
示例3: setUp
# 需要导入模块: from openedx.core.djangoapps.user_api.models import UserPreference [as 别名]
# 或者: from openedx.core.djangoapps.user_api.models.UserPreference import set_preference [as 别名]
def setUp(self):
# Platform language is English, instructor's language is Chinese,
# student's language is French, so the emails should all be sent in
# French.
self.course = CourseFactory.create()
self.instructor = InstructorFactory(course_key=self.course.id)
UserPreference.set_preference(self.instructor, LANGUAGE_KEY, 'zh-cn')
self.client.login(username=self.instructor.username, password='test')
self.student = UserFactory.create()
UserPreference.set_preference(self.student, LANGUAGE_KEY, 'fr')
示例4: set_language
# 需要导入模块: from openedx.core.djangoapps.user_api.models import UserPreference [as 别名]
# 或者: from openedx.core.djangoapps.user_api.models.UserPreference import set_preference [as 别名]
def set_language(request):
"""
This view is called when the user would like to set a language preference
"""
user = request.user
lang_pref = request.POST.get('language', None)
if lang_pref:
UserPreference.set_preference(user, LANGUAGE_KEY, lang_pref)
return HttpResponse('{"success": true}')
return HttpResponseBadRequest('no language provided')
示例5: test_language_in_user_prefs
# 需要导入模块: from openedx.core.djangoapps.user_api.models import UserPreference [as 别名]
# 或者: from openedx.core.djangoapps.user_api.models.UserPreference import set_preference [as 别名]
def test_language_in_user_prefs(self):
# language set in the user preferences and not the session
UserPreference.set_preference(self.user, LANGUAGE_KEY, 'eo')
self.middleware.process_request(self.request)
self.assertEquals(self.request.session['django_language'], 'eo')