當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。