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


Python translation.LANGUAGE_SESSION_KEY属性代码示例

本文整理汇总了Python中django.utils.translation.LANGUAGE_SESSION_KEY属性的典型用法代码示例。如果您正苦于以下问题:Python translation.LANGUAGE_SESSION_KEY属性的具体用法?Python translation.LANGUAGE_SESSION_KEY怎么用?Python translation.LANGUAGE_SESSION_KEY使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在django.utils.translation的用法示例。


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

示例1: logout

# 需要导入模块: from django.utils import translation [as 别名]
# 或者: from django.utils.translation import LANGUAGE_SESSION_KEY [as 别名]
def logout(request):
    """
    Removes the authenticated user's ID from the request and flushes their
    session data.
    """
    # Dispatch the signal before the user is logged out so the receivers have a
    # chance to find out *who* logged out.
    user = getattr(request, 'user', None)
    if hasattr(user, 'is_authenticated') and not user.is_authenticated():
        user = None
    user_logged_out.send(sender=user.__class__, request=request, user=user)

    # remember language choice saved to session
    language = request.session.get(LANGUAGE_SESSION_KEY)

    request.session.flush()

    if language is not None:
        request.session[LANGUAGE_SESSION_KEY] = language

    if hasattr(request, 'user'):
        from django.contrib.auth.models import AnonymousUser
        request.user = AnonymousUser() 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:25,代码来源:__init__.py

示例2: logout

# 需要导入模块: from django.utils import translation [as 别名]
# 或者: from django.utils.translation import LANGUAGE_SESSION_KEY [as 别名]
def logout(request):
    """
    Remove the authenticated user's ID from the request and flush their session
    data.
    """
    # Dispatch the signal before the user is logged out so the receivers have a
    # chance to find out *who* logged out.
    user = getattr(request, 'user', None)
    if hasattr(user, 'is_authenticated') and not user.is_authenticated:
        user = None
    user_logged_out.send(sender=user.__class__, request=request, user=user)

    # remember language choice saved to session
    language = request.session.get(LANGUAGE_SESSION_KEY)

    request.session.flush()

    if language is not None:
        request.session[LANGUAGE_SESSION_KEY] = language

    if hasattr(request, 'user'):
        from django.contrib.auth.models import AnonymousUser
        request.user = AnonymousUser() 
开发者ID:reBiocoder,项目名称:bioforum,代码行数:25,代码来源:__init__.py

示例3: process_response

# 需要导入模块: from django.utils import translation [as 别名]
# 或者: from django.utils.translation import LANGUAGE_SESSION_KEY [as 别名]
def process_response(self, request, response):
        if not hasattr(request, 'user'):
            return response

        if not request.user.is_authenticated:
            return response

        user_language = request.user.language
        current_language = translation.get_language()
        if user_language == current_language:
            return response

        translation.activate(user_language)
        request.session[translation.LANGUAGE_SESSION_KEY] = user_language

        return response 
开发者ID:Cadasta,项目名称:cadasta-platform,代码行数:18,代码来源:middleware.py

示例4: logout

# 需要导入模块: from django.utils import translation [as 别名]
# 或者: from django.utils.translation import LANGUAGE_SESSION_KEY [as 别名]
def logout(request):
    """
    Remove the authenticated user's ID from the request and flush their session
    data.
    """
    # Dispatch the signal before the user is logged out so the receivers have a
    # chance to find out *who* logged out.
    user = getattr(request, 'user', None)
    if not getattr(user, 'is_authenticated', True):
        user = None
    user_logged_out.send(sender=user.__class__, request=request, user=user)

    # remember language choice saved to session
    language = request.session.get(LANGUAGE_SESSION_KEY)

    request.session.flush()

    if language is not None:
        request.session[LANGUAGE_SESSION_KEY] = language

    if hasattr(request, 'user'):
        from django.contrib.auth.models import AnonymousUser
        request.user = AnonymousUser() 
开发者ID:PacktPublishing,项目名称:Hands-On-Application-Development-with-PyCharm,代码行数:25,代码来源:__init__.py

示例5: logout

# 需要导入模块: from django.utils import translation [as 别名]
# 或者: from django.utils.translation import LANGUAGE_SESSION_KEY [as 别名]
def logout(request):
    """
    Removes the authenticated user's ID from the request and flushes their
    session data.
    """
    # Dispatch the signal before the user is logged out so the receivers have a
    # chance to find out *who* logged out.
    user = getattr(request, 'user', None)
    if hasattr(user, 'is_authenticated') and not user.is_authenticated:
        user = None
    user_logged_out.send(sender=user.__class__, request=request, user=user)

    # remember language choice saved to session
    language = request.session.get(LANGUAGE_SESSION_KEY)

    request.session.flush()

    if language is not None:
        request.session[LANGUAGE_SESSION_KEY] = language

    if hasattr(request, 'user'):
        from django.contrib.auth.models import AnonymousUser
        request.user = AnonymousUser() 
开发者ID:bpgc-cte,项目名称:python2017,代码行数:25,代码来源:__init__.py

示例6: setlang

# 需要导入模块: from django.utils import translation [as 别名]
# 或者: from django.utils.translation import LANGUAGE_SESSION_KEY [as 别名]
def setlang(request):
    """
    Sets a user's language preference and redirects to a given URL or, by default, back to the previous page.
    """
    next = request.GET.get('next', None)
    if not is_safe_url(url=next, host=request.get_host()):
        next = request.META.get('HTTP_REFERER')
        if not is_safe_url(url=next, host=request.get_host()):
            next = '/'
    response = redirect(next)

    lang_code = request.GET.get('language', None)
    if lang_code and check_for_language(lang_code):
        if hasattr(request, 'session'):
            request.session[LANGUAGE_SESSION_KEY] = lang_code
        else:
            response.set_cookie(settings.LANGUAGE_COOKIE_NAME, lang_code,
                                max_age=settings.LANGUAGE_COOKIE_AGE,
                                path=settings.LANGUAGE_COOKIE_PATH,
                                domain=settings.LANGUAGE_COOKIE_DOMAIN)

    return response 
开发者ID:erigones,项目名称:esdc-ce,代码行数:24,代码来源:views.py

示例7: settings

# 需要导入模块: from django.utils import translation [as 别名]
# 或者: from django.utils.translation import LANGUAGE_SESSION_KEY [as 别名]
def settings(request):
    """User editing their profile."""
    title = _("Profile Settings")
    form = ProfileForm(instance=request.user)

    if request.method == "POST":

        form = ProfileForm(request.POST, request.FILES, instance=request.user)

        if form.is_valid():
            user = form.save()
            messages.success(request, _("Settings saved"))
            User.refresh_nomail()

            if form.cleaned_data['password1']:
                request.user.set_password(form.cleaned_data['password1'])
                request.user.save()

            lang = user.activate_locale()
            translation.activate(lang)
            request.session[translation.LANGUAGE_SESSION_KEY] = lang
            request.session['django_timezone'] = user.timezone

            return redirect(settings)
        else:
            messages.error(request, _("Error in profile data"))

    return render(request, "accounts/settings.html", locals()) 
开发者ID:fpsw,项目名称:Servo,代码行数:30,代码来源:account.py

示例8: init_locale

# 需要导入模块: from django.utils import translation [as 别名]
# 或者: from django.utils.translation import LANGUAGE_SESSION_KEY [as 别名]
def init_locale(request):
    """Initialize locale for the check-in interface."""
    lc = settings.INSTALL_LOCALE.split('.')
    locale.setlocale(locale.LC_TIME, lc)
    locale.setlocale(locale.LC_NUMERIC, lc)
    locale.setlocale(locale.LC_MESSAGES, lc)
    locale.setlocale(locale.LC_MONETARY, lc)

    translation.activate(settings.INSTALL_LANGUAGE)
    request.session[translation.LANGUAGE_SESSION_KEY] = settings.INSTALL_LANGUAGE 
开发者ID:fpsw,项目名称:Servo,代码行数:12,代码来源:checkin.py

示例9: about

# 需要导入模块: from django.utils import translation [as 别名]
# 或者: from django.utils.translation import LANGUAGE_SESSION_KEY [as 别名]
def about(request, lang):
    if lang != '':
        translation.activate(lang)
        request.session[translation.LANGUAGE_SESSION_KEY] = lang
    return render(request, 'about.html') 
开发者ID:mangaki,项目名称:mangaki,代码行数:7,代码来源:views.py

示例10: i18n_switcher

# 需要导入模块: from django.utils import translation [as 别名]
# 或者: from django.utils.translation import LANGUAGE_SESSION_KEY [as 别名]
def i18n_switcher(request, language):
    referer = get_referer(request, default='/')

    # set the new language
    translation.activate(language)
    request.session[translation.LANGUAGE_SESSION_KEY] = language

    return HttpResponseRedirect(referer)


# def return_settings(request):
#     data = {}
#     data['default_uri_prefix'] = settings.DEFAULT_URI_PREFIX
#     return HttpResponse(json.dumps(data), content_type='application/json') 
开发者ID:rdmorganiser,项目名称:rdmo,代码行数:16,代码来源:views.py

示例11: get_lang_from_session

# 需要导入模块: from django.utils import translation [as 别名]
# 或者: from django.utils.translation import LANGUAGE_SESSION_KEY [as 别名]
def get_lang_from_session(request, supported):
    if hasattr(request, "session"):
        lang_code = request.session.get(LANGUAGE_SESSION_KEY, None)
        if lang_code and lang_code in supported:
            return lang_code

    return None 
开发者ID:evernote,项目名称:zing,代码行数:9,代码来源:override.py

示例12: redirect_to_initiatives

# 需要导入模块: from django.utils import translation [as 别名]
# 或者: from django.utils.translation import LANGUAGE_SESSION_KEY [as 别名]
def redirect_to_initiatives(request, subpath):
    lang = request.LANGUAGE_CODE
    translation.activate(lang)
    request.session[translation.LANGUAGE_SESSION_KEY] = lang
    query_string = ""

    if request.META['QUERY_STRING']:
        query_string = f'?{request.META["QUERY_STRING"]}'

    return redirect(f'/{request.LANGUAGE_CODE}/initiatives/{subpath}{query_string}') 
开发者ID:mozilla,项目名称:foundation.mozilla.org,代码行数:12,代码来源:views.py

示例13: form_valid

# 需要导入模块: from django.utils import translation [as 别名]
# 或者: from django.utils.translation import LANGUAGE_SESSION_KEY [as 别名]
def form_valid(self, form):
        self.object = form.save()
        translation.activate(self.object.language)
        self.request.session[
            translation.LANGUAGE_SESSION_KEY
        ] = self.object.language
        return self.success_redirect(_(u'Language changed.')) 
开发者ID:luanfonceca,项目名称:speakerfight,代码行数:9,代码来源:views.py

示例14: test_logout_preserve_language

# 需要导入模块: from django.utils import translation [as 别名]
# 或者: from django.utils.translation import LANGUAGE_SESSION_KEY [as 别名]
def test_logout_preserve_language(self):
        """Language stored in session is preserved after logout"""
        # Create a new session with language
        engine = import_module(settings.SESSION_ENGINE)
        session = engine.SessionStore()
        session[LANGUAGE_SESSION_KEY] = 'pl'
        session.save()
        self.client.cookies[settings.SESSION_COOKIE_NAME] = session.session_key

        self.client.get('/logout/')
        self.assertEqual(self.client.session[LANGUAGE_SESSION_KEY], 'pl') 
开发者ID:nesdis,项目名称:djongo,代码行数:13,代码来源:test_views.py

示例15: activate_locale

# 需要导入模块: from django.utils import translation [as 别名]
# 或者: from django.utils.translation import LANGUAGE_SESSION_KEY [as 别名]
def activate_locale(self, request):
        """
        Save language and timezone settings from profile into session.
        The settings are read by django middleware.
        """
        request.session[LANGUAGE_SESSION_KEY] = str(self.language)
        request.session[settings.TIMEZONE_SESSION_KEY] = str(self.timezone) 
开发者ID:erigones,项目名称:esdc-ce,代码行数:9,代码来源:userprofile.py


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