Beispiel #1
0
def language_info(request):
    """Retrieve information about languages.

    Gets the user's preferred language and the list of released
    languages, encoding the information as JSON.

    Args:
        request (HttpRequest)

    Returns:
        HttpResponse: 200 if successful on GET
        HttpResponse: 302 if not logged in (redirect to login page)
        HttpResponse: 405 if using an unsupported HTTP method
        HttpResponse: 500 if an unexpected error occurs

    Example:

        GET /profile/preferences/languages

    """
    user = request.user

    preferred_language_code = profile_api.preference_info(user.username).get(LANGUAGE_KEY)
    preferred_language = language_api.preferred_language(preferred_language_code)
    response_data = {'preferredLanguage': {'code': preferred_language.code, 'name': preferred_language.name}}

    languages = language_api.released_languages()
    response_data['languages'] = [{'code': language.code, 'name': language.name} for language in languages]

    return HttpResponse(json.dumps(response_data), content_type='application/json')
Beispiel #2
0
def index(request):
    """Render the profile info page.

    Args:
        request (HttpRequest)

    Returns:
        HttpResponse: 200 if successful
        HttpResponse: 302 if not logged in (redirect to login page)
        HttpResponse: 405 if using an unsupported HTTP method

    Example:

        GET /profile

    """
    user = request.user

    released_languages = language_api.released_languages()

    preferred_language_code = profile_api.preference_info(user.username).get(LANGUAGE_KEY)
    preferred_language = language_api.preferred_language(preferred_language_code)

    context = {
        'disable_courseware_js': True,
        'released_languages': released_languages,
        'preferred_language': preferred_language,
    }

    if settings.FEATURES.get('ENABLE_THIRD_PARTY_AUTH'):
        context['provider_user_states'] = pipeline.get_provider_user_states(user)

    return render_to_response('student_profile/index.html', context)
Beispiel #3
0
def language_info(request):
    """Retrieve information about languages.

    Gets the user's preferred language and the list of released
    languages, encoding the information as JSON.

    Args:
        request (HttpRequest)

    Returns:
        HttpResponse: 200 if successful on GET
        HttpResponse: 302 if not logged in (redirect to login page)
        HttpResponse: 405 if using an unsupported HTTP method
        HttpResponse: 500 if an unexpected error occurs

    Example:

        GET /profile/preferences/languages

    """
    user = request.user

    preferred_language_code = profile_api.preference_info(user.username).get(LANGUAGE_KEY)
    preferred_language = language_api.preferred_language(preferred_language_code)
    response_data = {'preferredLanguage': {'code': preferred_language.code, 'name': preferred_language.name}}

    languages = language_api.released_languages()
    response_data['languages'] = [{'code': language.code, 'name': language.name} for language in languages]

    return HttpResponse(json.dumps(response_data), content_type='application/json')
Beispiel #4
0
def index(request):
    """Render the profile info page.

    Args:
        request (HttpRequest)

    Returns:
        HttpResponse: 200 if successful
        HttpResponse: 302 if not logged in (redirect to login page)
        HttpResponse: 405 if using an unsupported HTTP method

    Example:

        GET /profile

    """
    user = request.user

    released_languages = language_api.released_languages()

    preferred_language_code = profile_api.preference_info(
        user.username).get(LANGUAGE_KEY)
    preferred_language = language_api.preferred_language(
        preferred_language_code)

    context = {
        'disable_courseware_js': True,
        'released_languages': released_languages,
        'preferred_language': preferred_language,
    }

    if settings.FEATURES.get('ENABLE_THIRD_PARTY_AUTH'):
        context['provider_user_states'] = pipeline.get_provider_user_states(
            user)

    return render_to_response('student_profile/index.html', context)
Beispiel #5
0
 def test_no_preferred_language(self):
     preferred_language = language_api.preferred_language(None)
     self.assertEqual(preferred_language, u'English')
Beispiel #6
0
 def test_invalid_preferred_language(self, language_code):
     preferred_language = language_api.preferred_language(language_code)
     self.assertEqual(preferred_language, u'English')
Beispiel #7
0
 def test_preferred_language(self):
     preferred_language = language_api.preferred_language('fr')
     self.assertEqual(preferred_language, u'Français')