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


Python Entity.map_entities方法代码示例

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


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

示例1: test_entity_project_locale_order

# 需要导入模块: from pontoon.base.models import Entity [as 别名]
# 或者: from pontoon.base.models.Entity import map_entities [as 别名]
def test_entity_project_locale_order(entity_test_models):
    """
    Return entities in correct order.
    """
    resource0 = entity_test_models[0].entity.resource
    locale_a = entity_test_models[0].locale
    project_a = resource0.project
    EntityFactory.create(
        order=2,
        resource=resource0,
        string='Second String',
    )
    EntityFactory.create(
        order=1,
        resource=resource0,
        string='First String',
    )
    entities = Entity.map_entities(
        locale_a,
        Entity.for_project_locale(
            project_a,
            locale_a,
        ),
    )
    assert entities[1]['original'] == 'First String'
    assert entities[2]['original'] == 'Second String'
开发者ID:Pike,项目名称:pontoon,代码行数:28,代码来源:test_entity.py

示例2: test_entity_project_locale_subpages

# 需要导入模块: from pontoon.base.models import Entity [as 别名]
# 或者: from pontoon.base.models.Entity import map_entities [as 别名]
def test_entity_project_locale_subpages(entity_test_models):
    """
    If paths specified as subpages, return project entities from paths
    assigned to these subpages only along with their translations for
    locale.
    """
    tr0 = entity_test_models[0]
    subpageX = entity_test_models[3]
    locale_a = tr0.locale
    entity_a = tr0.entity
    resource0 = tr0.entity.resource
    project_a = tr0.entity.resource.project
    subpages = [subpageX.name]
    entities = Entity.map_entities(
        locale_a,
        Entity.for_project_locale(
            project_a,
            locale_a,
            subpages,
        ),
    )
    assert len(entities) == 1
    assert entities[0]['path'] == resource0.path
    assert entities[0]['original'] == entity_a.string
    assert entities[0]['translation'][0]['string'] == tr0.string
开发者ID:Pike,项目名称:pontoon,代码行数:27,代码来源:test_entity.py

示例3: _get_entities_list

# 需要导入模块: from pontoon.base.models import Entity [as 别名]
# 或者: from pontoon.base.models.Entity import map_entities [as 别名]
def _get_entities_list(locale, project, form):
    """Return a specific list of entities, as defined by the `entity_ids` field of the form.

    This is used for batch editing.
    """
    entities = (
        Entity.objects.filter(pk__in=form.cleaned_data['entity_ids'])
        .distinct()
        .order_by('order')
    )

    return JsonResponse({
        'entities': Entity.map_entities(locale, entities),
        'stats': TranslatedResource.objects.stats(
            project, form.cleaned_data['paths'], locale
        ),
    }, safe=False)
开发者ID:Pike,项目名称:pontoon,代码行数:19,代码来源:views.py

示例4: test_entity_project_locale_cleaned_key

# 需要导入模块: from pontoon.base.models import Entity [as 别名]
# 或者: from pontoon.base.models.Entity import map_entities [as 别名]
def test_entity_project_locale_cleaned_key(entity_test_models):
    """
    If key contanis source string and Translate Toolkit separator,
    remove them.
    """
    resource0 = entity_test_models[0].entity.resource
    locale_a = entity_test_models[0].locale
    project_a = resource0.project
    entities = Entity.map_entities(
        locale_a,
        Entity.for_project_locale(
            project_a,
            locale_a,
        ),
    )
    assert entities[0]['key'] == ''
    assert entities[1]['key'] == 'Key'
开发者ID:Pike,项目名称:pontoon,代码行数:19,代码来源:test_entity.py

示例5: _get_all_entities

# 需要导入模块: from pontoon.base.models import Entity [as 别名]
# 或者: from pontoon.base.models.Entity import map_entities [as 别名]
def _get_all_entities(locale, project, form, entities):
    """Return entities without pagination.

    This is used by the in-context mode of the Translate page.
    """
    has_next = False
    entities_to_map = Entity.for_project_locale(
        project,
        locale,
        paths=form.cleaned_data['paths'],
        exclude_entities=form.cleaned_data['exclude_entities']
    )
    visible_entities = entities.values_list('pk', flat=True)

    return JsonResponse({
        'entities': Entity.map_entities(locale, entities_to_map, visible_entities),
        'has_next': has_next,
        'stats': TranslatedResource.objects.stats(
            project, form.cleaned_data['paths'], locale
        ),
    }, safe=False)
开发者ID:Pike,项目名称:pontoon,代码行数:23,代码来源:views.py

示例6: test_entity_project_locale_paths

# 需要导入模块: from pontoon.base.models import Entity [as 别名]
# 或者: from pontoon.base.models.Entity import map_entities [as 别名]
def test_entity_project_locale_paths(entity_test_models):
    """
    If paths specified, return project entities from these paths only along
    with their translations for locale.
    """
    tr0, tr0pl, trX, subpageX = entity_test_models
    locale_a = tr0.locale
    project_a = tr0.entity.resource.project
    paths = ['resourceX.po']
    entities = Entity.map_entities(
        locale_a,
        Entity.for_project_locale(
            project_a,
            locale_a,
            paths,
        ),
    )
    assert len(entities) == 1
    assert entities[0]['path'] == trX.entity.resource.path
    assert entities[0]['original'] == trX.entity.string
    assert entities[0]['translation'][0]['string'] == trX.string
开发者ID:Pike,项目名称:pontoon,代码行数:23,代码来源:test_entity.py

示例7: test_entity_project_locale_plurals

# 需要导入模块: from pontoon.base.models import Entity [as 别名]
# 或者: from pontoon.base.models.Entity import map_entities [as 别名]
def test_entity_project_locale_plurals(
    entity_test_models,
    locale_b,
    project_b,
):
    """
    For pluralized strings, return all available plural forms.
    """
    tr0, tr0pl, trX, subpageX = entity_test_models
    locale_a = tr0.locale
    entity_a = tr0.entity
    project_a = tr0.entity.resource.project
    entities = Entity.map_entities(
        locale_a,
        Entity.for_project_locale(
            project_a,
            locale_a,
        ),
    )
    assert entities[0]['original'] == entity_a.string
    assert entities[0]['original_plural'] == entity_a.string_plural
    assert entities[0]['translation'][0]['string'] == tr0.string
    assert entities[0]['translation'][1]['string'] == tr0pl.string
开发者ID:Pike,项目名称:pontoon,代码行数:25,代码来源:test_entity.py

示例8: _get_paginated_entities

# 需要导入模块: from pontoon.base.models import Entity [as 别名]
# 或者: from pontoon.base.models.Entity import map_entities [as 别名]
def _get_paginated_entities(locale, project, form, entities):
    """Return a paginated list of entities.

    This is used by the regular mode of the Translate page.
    """
    paginator = Paginator(entities, form.cleaned_data['limit'])

    try:
        entities_page = paginator.page(1)
    except EmptyPage:
        return JsonResponse({
            'has_next': False,
            'stats': {},
        })

    has_next = entities_page.has_next()
    entities_to_map = entities_page.object_list

    # If requested entity not on the first page
    if form.cleaned_data['entity']:
        entity_pk = form.cleaned_data['entity']
        entities_to_map_pks = [e.pk for e in entities_to_map]

        # TODO: entities_to_map.values_list() doesn't return entities from selected page
        if entity_pk not in entities_to_map_pks:
            if entity_pk in entities.values_list('pk', flat=True):
                entities_to_map_pks.append(entity_pk)
                entities_to_map = entities.filter(pk__in=entities_to_map_pks)

    return JsonResponse({
        'entities': Entity.map_entities(locale, entities_to_map, []),
        'has_next': has_next,
        'stats': TranslatedResource.objects.stats(
            project, form.cleaned_data['paths'], locale
        ),
    }, safe=False)
开发者ID:Pike,项目名称:pontoon,代码行数:38,代码来源:views.py

示例9: entities

# 需要导入模块: from pontoon.base.models import Entity [as 别名]
# 或者: from pontoon.base.models.Entity import map_entities [as 别名]
def entities(request):
    """Get entities for the specified project, locale and paths."""
    try:
        project = request.POST['project']
        locale = request.POST['locale']
        paths = request.POST.getlist('paths[]')
        limit = int(request.POST.get('limit', 50))
    except (MultiValueDictKeyError, ValueError) as err:
        return HttpResponseBadRequest('Bad Request: {error}'.format(error=err))

    project = get_object_or_404(Project, slug=project)
    locale = get_object_or_404(Locale, code__iexact=locale)

    filter_type = request.POST.get('filter', '')
    search = request.POST.get('search', '')
    exclude_entities = request.POST.getlist('excludeEntities[]', [])

    # Only return entities with provided IDs
    entity_ids = request.POST.getlist('entityIds[]', [])
    if entity_ids:
        entities = (
            Entity.objects.filter(pk__in=entity_ids)
            .prefetch_resources_translations(locale)
            .distinct()
            .order_by('order')
        )

        return JsonResponse({
            'entities': Entity.map_entities(locale, entities),
            'stats': TranslatedResource.objects.stats(project, paths, locale),
        }, safe=False)

    entities = Entity.for_project_locale(
        project, locale, paths, filter_type, search, exclude_entities
    )

    # Only return a list of entity PKs
    if request.POST.get('pkOnly', None):
        return JsonResponse({
            'entity_pks': list(entities.values_list('pk', flat=True)),
        })

    visible_entities = []

    # In-place view: load all entities
    if request.POST.get('inplaceEditor', None):
        has_next = False
        entities_to_map = Entity.for_project_locale(
            project, locale, paths, None, None, exclude_entities
        )
        visible_entities = entities.values_list('pk', flat=True)

    # Out-of-context view: paginate entities
    else:
        paginator = Paginator(entities, limit)

        try:
            entities_page = paginator.page(1)
        except EmptyPage:
            return JsonResponse({
                'has_next': False,
                'stats': {},
            })

        has_next = entities_page.has_next()
        entities_to_map = entities_page.object_list

        # If requested entity not on the first page
        entity = request.POST.get('entity', None)
        if entity:
            entity_pk = int(entity)
            # TODO: entities_to_map.values_list() doesn't return entities from selected page
            if entity_pk not in [e.pk for e in entities_to_map]:
                if entity_pk in entities.values_list('pk', flat=True):
                    entities_to_map = list(entities_to_map) + list(entities.filter(pk=entity_pk))

    return JsonResponse({
        'entities': Entity.map_entities(locale, entities_to_map, visible_entities),
        'has_next': has_next,
        'stats': TranslatedResource.objects.stats(project, paths, locale),
    }, safe=False)
开发者ID:CE-OP,项目名称:pontoon,代码行数:83,代码来源:views.py

示例10: test_entity_project_locale_no_paths

# 需要导入模块: from pontoon.base.models import Entity [as 别名]
# 或者: from pontoon.base.models.Entity import map_entities [as 别名]
def test_entity_project_locale_no_paths(
    entity_test_models,
    locale_b,
    project_b,
):
    """
    If paths not specified, return all project entities along with their
    translations for locale.
    """
    tr0, tr0pl, trX, subpageX = entity_test_models
    locale_a = tr0.locale
    entity_a = tr0.entity
    resource0 = tr0.entity.resource
    project_a = tr0.entity.resource.project
    entities = Entity.map_entities(
        locale_a,
        Entity.for_project_locale(project_a, locale_a),
    )
    assert len(entities) == 2
    assert entities[0]['path'] == resource0.path
    assert entities[0]['original'] == entity_a.string
    assert entities[0]['translation'][0]['string'] == tr0.string
    assert entities[1]['path'] == trX.entity.resource.path
    assert entities[1]['original'] == trX.entity.string
    assert entities[1]['translation'][0]['string'] == trX.string

    # Ensure all attributes are assigned correctly
    expected = {
        'comment': '',
        'format': 'po',
        'obsolete': False,
        'marked': unicode(entity_a.string),
        'key': '',
        'path': unicode(resource0.path),
        'project': project_a.serialize(),
        'translation': [
            {
                'pk': tr0.pk,
                'fuzzy': False,
                'string': unicode(tr0.string),
                'approved': False,
                'rejected': False,
                'warnings': [],
                'errors': [],
            },
            {
                'pk': tr0pl.pk,
                'fuzzy': False,
                'string': unicode(tr0pl.string),
                'approved': False,
                'rejected': False,
                'warnings': [],
                'errors': [],
            },
        ],
        'order': 0,
        'source': [],
        'original_plural': unicode(entity_a.string_plural),
        'marked_plural': unicode(entity_a.string_plural),
        'pk': entity_a.pk,
        'original': unicode(entity_a.string),
        'readonly': False,
        'visible': False,
    }
    assert entities[0] == expected
开发者ID:Pike,项目名称:pontoon,代码行数:67,代码来源:test_entity.py

示例11: entities

# 需要导入模块: from pontoon.base.models import Entity [as 别名]
# 或者: from pontoon.base.models.Entity import map_entities [as 别名]
def entities(request):
    """Get entities for the specified project, locale and paths."""
    try:
        project = request.POST["project"]
        locale = request.POST["locale"]
        paths = request.POST.getlist("paths[]")
        limit = int(request.POST.get("limit", 50))
    except (MultiValueDictKeyError, ValueError) as e:
        return HttpResponseBadRequest("Bad Request: {error}".format(error=e))

    project = get_object_or_404(Project, slug=project)
    locale = get_object_or_404(Locale, code__iexact=locale)

    filter_type = request.POST.get("filterType", "")
    search = request.POST.get("search", "")
    exclude_entities = request.POST.getlist("excludeEntities[]", [])

    # Only return entities with provided IDs
    entity_ids = request.POST.getlist("entityIds[]", [])
    if entity_ids:
        entities = (
            Entity.objects.filter(pk__in=entity_ids)
            .prefetch_resources_translations(locale)
            .distinct()
            .order_by("order")
        )

        return JsonResponse(
            {
                "entities": Entity.map_entities(locale, entities),
                "stats": TranslatedResource.objects.stats(project, paths, locale),
            },
            safe=False,
        )

    entities = Entity.for_project_locale(project, locale, paths, filter_type, search, exclude_entities)

    # Only return a list of entity PKs
    if request.POST.get("pkOnly", None):
        return JsonResponse({"entity_pks": list(entities.values_list("pk", flat=True))})

    # In-place view: load all entities
    if request.POST.get("inplaceEditor", None):
        has_next = False
        entities_to_map = entities

    # Out-of-context view: paginate entities
    else:
        paginator = Paginator(entities, limit)

        try:
            entities_page = paginator.page(1)
        except EmptyPage:
            return JsonResponse({"has_next": False, "stats": {}})

        has_next = entities_page.has_next()
        entities_to_map = entities_page.object_list

    return JsonResponse(
        {
            "entities": Entity.map_entities(locale, entities_to_map),
            "has_next": has_next,
            "stats": TranslatedResource.objects.stats(project, paths, locale),
        },
        safe=False,
    )
开发者ID:mastizada,项目名称:pontoon,代码行数:68,代码来源:views.py


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