Example #1
0
def set_language(request):
    """
    It does everything in the django set_language, plus assigning language
    to request.user.profile.

    Below is the behavior of django set_languate:

    Redirect to a given url while setting the chosen language in the
    session or cookie. The url and the language code need to be
    specified in the request parameters.

    Since this view changes how the user will see the rest of the site, it must
    only be accessed as a POST request. If called as a GET request, it will
    redirect to the page in the request (the 'next' parameter) without changing
    any state.
    """
    if not settings.USE_I18N:
        raise Http404
    response = dj_set_language(request)
    if request.method == 'POST':
        lang_code = request.POST.get('language', None)
        if lang_code and check_for_language(lang_code):
            profile = request.user.profile
            profile.language = lang_code
            profile.save()
    return response
Example #2
0
def set_language(request):
    """
    It does everything in the django set_language, plus assigning language
    to request.user.profile.

    Below is the behavior of django set_languate:

    Redirect to a given url while setting the chosen language in the
    session or cookie. The url and the language code need to be
    specified in the request parameters.

    Since this view changes how the user will see the rest of the site, it must
    only be accessed as a POST request. If called as a GET request, it will
    redirect to the page in the request (the 'next' parameter) without changing
    any state.
    """
    if not settings.USE_I18N:
        raise Http404
    response = dj_set_language(request)
    if request.method == 'POST':
        lang_code = request.POST.get('language', None)
        if lang_code and check_for_language(lang_code):
            profile = request.user.profile
            profile.language = lang_code
            profile.save()
    return response
Example #3
0
def set_language(request):
    """
    A wrapper arround :func:`django.views.i18n.set_language` that
    stores the language in the user profile.
    """
    response = dj_set_language(request)
    if request.method == "POST" and request.user.is_authenticated():
        language = request.session.get('django_language')
        if language:
            request.user.profile.language = language
            request.user.profile.save()
    return response
Example #4
0
def set_language(request):
    """
    A wrapper arround :func:`django.views.i18n.set_language` that
    stores the language in the user profile.
    """
    response = dj_set_language(request)
    if request.method == "POST" and request.user.is_authenticated():
        language = request.session.get('django_language')
        if language:
            request.user.profile.language = language
            request.user.profile.save()
    return response