Exemplo n.º 1
0
def test_get_languages_no_permissions(config, root, dummy_request):
    from kotti_multilingual.api import get_languages
    from kotti_multilingual.resources import LanguageRoot

    root['de'] = LanguageRoot(language=u'de')
    assert get_languages(dummy_request) == [
        {'id': u'de', 'title': u'Deutsch', 'url': u'http://example.com/de/'}]
    config.testing_securitypolicy(permissive=False)
    assert get_languages(dummy_request) == []
Exemplo n.º 2
0
def test_get_languages_no_request(root):
    from kotti_multilingual.api import get_languages
    from kotti_multilingual.resources import LanguageRoot

    root['de'] = LanguageRoot(language=u'de')

    assert get_languages() == [{'id': u'de', 'title': u'Deutsch'}]
Exemplo n.º 3
0
def test_get_languages_request(root, dummy_request):
    from kotti_multilingual.api import get_languages
    from kotti_multilingual.resources import LanguageRoot

    root['de'] = LanguageRoot(language=u'de')

    assert get_languages(dummy_request) == [
        {'id': u'de', 'title': u'Deutsch', 'url': u'http://example.com/de/'}]
Exemplo n.º 4
0
def test_get_languages_order(root, dummy_request):
    from kotti_multilingual.api import get_languages
    from kotti_multilingual.resources import LanguageRoot

    root['de'] = LanguageRoot(language=u'de')
    root['sl'] = LanguageRoot(language=u'sl')
    root['hu'] = LanguageRoot(language=u'hu')

    assert get_languages() == [
        {'id': u'de', 'title': u'Deutsch'},
        {'id': u'sl', 'title': u'sloven\u0161\u010dina'},
        {'id': u'hu', 'title': u'magyar'}
    ]

    de, sl, hu = root.values()
    root.children[:] = [sl, hu, de]

    assert get_languages() == [
        {'id': u'sl', 'title': u'sloven\u0161\u010dina'},
        {'id': u'hu', 'title': u'magyar'},
        {'id': u'de', 'title': u'Deutsch'}
    ]
Exemplo n.º 5
0
def translation_dropdown(context, request):
    languages = api.get_languages(request)
    translations = api.get_translations(context)
    translatable_into = []

    for lang in languages:
        if lang['id'] in translations or lang['id'] == context.language:
            continue
        translated_parent = find_parent(
            context.__parent__,
            lambda item: lang['id'] in api.get_translations(item))
        if translated_parent is None:
            continue
        container = api.get_translations(translated_parent).get(lang['id'])
        url = request.resource_url(
            container,
            'add-translation',
            query={'id': context.id}
        )

        if has_permission('add', container, request):
            translatable_into.append({
                'language': lang['id'],
                'title': lang['title'],
                'url': url
            })
    translations = [
        {
            'language': tr.language,
            'title': api.get_language_title(tr.language),
            'url': request.resource_url(tr),
        } for tr in translations.values()
    ]
    return {
        'translations': translations,
        'translatable_into': translatable_into
    }
Exemplo n.º 6
0
def test_get_languages_no_language_root(root):
    from kotti_multilingual.api import get_languages

    assert get_languages() == []
Exemplo n.º 7
0
def add_renderer_globals(event):
    if event['renderer_name'] != 'json':
        request = event['request']
        event['languages'] = get_languages(request=request)