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


Python Entity.for_project_locale方法代码示例

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


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

示例1: test_for_project_locale_filter

# 需要导入模块: from pontoon.base.models import Entity [as 别名]
# 或者: from pontoon.base.models.Entity import for_project_locale [as 别名]
 def test_for_project_locale_filter(self):
     """
     Evaluate entities filtering by locale, project, obsolete.
     """
     other_locale = LocaleFactory.create()
     other_project = ProjectFactory.create(locales=[self.locale, other_locale])
     obsolete_entity = EntityFactory.create(obsolete=True, resource=self.main_resource, string="Obsolete String")
     entities = Entity.for_project_locale(self.project, other_locale)
     assert_equal(len(entities), 0)
     entities = Entity.for_project_locale(other_project, self.locale)
     assert_equal(len(entities), 0)
     entities = Entity.for_project_locale(self.project, self.locale)
     assert_equal(len(entities), 2)
开发者ID:riseofthetigers,项目名称:pontoon,代码行数:15,代码来源:test_models.py

示例2: test_entity_project_locale_subpages

# 需要导入模块: from pontoon.base.models import Entity [as 别名]
# 或者: from pontoon.base.models.Entity import for_project_locale [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: test_entity_project_locale_order

# 需要导入模块: from pontoon.base.models import Entity [as 别名]
# 或者: from pontoon.base.models.Entity import for_project_locale [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

示例4: entities

# 需要导入模块: from pontoon.base.models import Entity [as 别名]
# 或者: from pontoon.base.models.Entity import for_project_locale [as 别名]
def entities(request, template=None):
    """Get entities for the specified project, locale and paths."""
    log.debug("Get entities for the specified project, locale and paths.")

    if not request.is_ajax():
        log.error("Non-AJAX request")
        raise Http404

    try:
        project = request.GET['project']
        locale = request.GET['locale']
        paths = json.loads(request.GET['paths'])
    except MultiValueDictKeyError as e:
        log.error(str(e))
        return HttpResponse("error")

    log.debug("Project: " + project)
    log.debug("Locale: " + locale)
    log.debug("Paths: " + str(paths))

    try:
        project = Project.objects.get(pk=project)
    except Entity.DoesNotExist as e:
        log.error(str(e))
        return HttpResponse("error")

    try:
        locale = Locale.objects.get(code__iexact=locale)
    except Locale.DoesNotExist as e:
        log.error(str(e))
        return HttpResponse("error")

    entities = Entity.for_project_locale(project, locale, paths)
    return HttpResponse(json.dumps(entities), content_type='application/json')
开发者ID:m8ttyB,项目名称:pontoon,代码行数:36,代码来源:views.py

示例5: entities

# 需要导入模块: from pontoon.base.models import Entity [as 别名]
# 或者: from pontoon.base.models.Entity import for_project_locale [as 别名]
def entities(request):
    """Get entities for the specified project, locale and paths."""
    try:
        project = request.GET['project']
        locale = request.GET['locale']
        paths = json.loads(request.GET['paths'])
    except MultiValueDictKeyError as e:
        log.error(str(e))
        return HttpResponse("error")

    try:
        project = Project.objects.get(slug=project)
    except Entity.DoesNotExist as e:
        log.error(str(e))
        return HttpResponse("error")

    try:
        locale = Locale.objects.get(code__iexact=locale)
    except Locale.DoesNotExist as e:
        log.error(str(e))
        return HttpResponse("error")

    search = None
    if request.GET.get('keyword', None):
        search = request.GET

    entities = Entity.for_project_locale(project, locale, paths, search)
    return HttpResponse(json.dumps(entities), content_type='application/json')
开发者ID:waseem18,项目名称:pontoon,代码行数:30,代码来源:views.py

示例6: entities

# 需要导入模块: from pontoon.base.models import Entity [as 别名]
# 或者: from pontoon.base.models.Entity import for_project_locale [as 别名]
def entities(request):
    """Get entities for the specified project, locale and paths."""
    form = forms.GetEntitiesForm(request.POST)
    if not form.is_valid():
        return HttpResponseBadRequest(form.errors.as_json())

    project = get_object_or_404(Project, slug=form.cleaned_data['project'])
    locale = get_object_or_404(Locale, code=form.cleaned_data['locale'])

    # Only return entities with provided IDs (batch editing)
    if form.cleaned_data['entity_ids']:
        return _get_entities_list(locale, project, form)

    # `Entity.for_project_locale` only requires a subset of the fields the form contains. We thus
    # make a new dict with only the keys we want to pass to that function.
    restrict_to_keys = (
        'paths', 'status', 'search', 'exclude_entities', 'extra', 'time', 'author',
    )
    form_data = {k: form.cleaned_data[k] for k in restrict_to_keys if k in form.cleaned_data}

    entities = Entity.for_project_locale(project, locale, **form_data)

    # Only return a list of entity PKs (batch editing: select all)
    if form.cleaned_data['pk_only']:
        return JsonResponse({
            'entity_pks': list(entities.values_list('pk', flat=True)),
        })

    # In-place view: load all entities
    if form.cleaned_data['inplace_editor']:
        return _get_all_entities(locale, project, form, entities)

    # Out-of-context view: paginate entities
    return _get_paginated_entities(locale, project, form, entities)
开发者ID:MikkCZ,项目名称:pontoon,代码行数:36,代码来源:views.py

示例7: test_entity_project_locale_filter

# 需要导入模块: from pontoon.base.models import Entity [as 别名]
# 或者: from pontoon.base.models.Entity import for_project_locale [as 别名]
def test_entity_project_locale_filter(entity_test_models, locale_b, project_b):
    """
    Evaluate entities filtering by locale, project, obsolete.
    """
    tr0, tr0pl, trX, subpageX = entity_test_models
    locale_a = tr0.locale
    resource0 = tr0.entity.resource
    project_a = tr0.entity.resource.project
    EntityFactory.create(
        obsolete=True,
        resource=resource0,
        string='Obsolete String',
    )
    assert len(Entity.for_project_locale(project_a, locale_b)) == 0
    assert len(Entity.for_project_locale(project_b, locale_a)) == 0
    assert len(Entity.for_project_locale(project_a, locale_a)) == 2
开发者ID:Pike,项目名称:pontoon,代码行数:18,代码来源:test_entity.py

示例8: test_entity_project_locale_tags

# 需要导入模块: from pontoon.base.models import Entity [as 别名]
# 或者: from pontoon.base.models.Entity import for_project_locale [as 别名]
def test_entity_project_locale_tags(entity_a, locale_a, tag_a):
    """ Test filtering of tags in for_project_locale
    """
    resource = entity_a.resource
    project = resource.project
    entities = Entity.for_project_locale(
        project, locale_a, tag=tag_a.slug,
    )
    assert entity_a in entities

    # remove the resource <> tag association
    resource.tag_set.remove(tag_a)

    entities = Entity.for_project_locale(
        project, locale_a, tag=tag_a.slug,
    )
    assert entity_a not in entities
开发者ID:Pike,项目名称:pontoon,代码行数:19,代码来源:test_entity.py

示例9: test_for_project_locale_cleaned_key

# 需要导入模块: from pontoon.base.models import Entity [as 别名]
# 或者: from pontoon.base.models.Entity import for_project_locale [as 别名]
    def test_for_project_locale_cleaned_key(self):
        """
        If key contais source string and Translate Toolkit separator,
        remove them.
        """
        entities = Entity.for_project_locale(self.project, self.locale)

        assert_equal(entities[0]["key"], "")
        assert_equal(entities[1]["key"], "Key")
开发者ID:dsaumyajit007,项目名称:pontoon,代码行数:11,代码来源:test_models.py

示例10: test_for_project_locale_plurals

# 需要导入模块: from pontoon.base.models import Entity [as 别名]
# 或者: from pontoon.base.models.Entity import for_project_locale [as 别名]
    def test_for_project_locale_plurals(self):
        """
        For pluralized strings, return all available plural forms.
        """
        entities = Entity.for_project_locale(self.project, self.locale)

        assert_equal(entities[0]['original'], 'Source String')
        assert_equal(entities[0]['original_plural'], 'Plural Source String')
        assert_equal(entities[0]['translation'][0]['string'], 'Translated String')
        assert_equal(entities[0]['translation'][1]['string'], 'Translated Plural String')
开发者ID:rajul,项目名称:pontoon,代码行数:12,代码来源:test_models.py

示例11: test_for_project_locale_order

# 需要导入模块: from pontoon.base.models import Entity [as 别名]
# 或者: from pontoon.base.models.Entity import for_project_locale [as 别名]
    def test_for_project_locale_order(self):
        """
        Return entities in correct order.
        """
        entity_second = EntityFactory.create(order=1, resource=self.main_resource, string="Second String")
        entity_first = EntityFactory.create(order=0, resource=self.main_resource, string="First String")
        entities = Entity.for_project_locale(self.project, self.locale)

        assert_equal(entities[2]["original"], "First String")
        assert_equal(entities[3]["original"], "Second String")
开发者ID:riseofthetigers,项目名称:pontoon,代码行数:12,代码来源:test_models.py

示例12: test_for_project_locale_paths

# 需要导入模块: from pontoon.base.models import Entity [as 别名]
# 或者: from pontoon.base.models.Entity import for_project_locale [as 别名]
    def test_for_project_locale_paths(self):
        """
        If paths specified, return project entities from these paths only along
        with their translations for locale.
        """
        paths = ["other.lang"]
        entities = Entity.for_project_locale(self.project, self.locale, paths)

        assert_equal(len(entities), 1)
        self.assert_serialized_entity(entities[0], "other.lang", "Other Source String", "Other Translated String")
开发者ID:dsaumyajit007,项目名称:pontoon,代码行数:12,代码来源:test_models.py

示例13: test_for_project_locale_subpages

# 需要导入模块: from pontoon.base.models import Entity [as 别名]
# 或者: from pontoon.base.models.Entity import for_project_locale [as 别名]
    def test_for_project_locale_subpages(self):
        """
        If paths specified as subpages, return project entities from paths
        assigned to these subpages only along with their translations for
        locale.
        """
        subpages = [self.subpage.name]
        entities = Entity.for_project_locale(self.project, self.locale, subpages)

        assert_equal(len(entities), 1)
        self.assert_serialized_entity(entities[0], "main.lang", "Source String", "Translated String")
开发者ID:dsaumyajit007,项目名称:pontoon,代码行数:13,代码来源:test_models.py

示例14: test_mgr_entity_filter_combined

# 需要导入模块: from pontoon.base.models import Entity [as 别名]
# 或者: from pontoon.base.models.Entity import for_project_locale [as 别名]
def test_mgr_entity_filter_combined(resource_a, locale_a, user_a):
    """
    All filters should be joined by AND instead of OR.
    Tests filters against bug introduced by bug 1243115.
    """
    entities = [
        EntityFactory.create(
            resource=resource_a,
            string="testentity%s" % i,
        ) for i in range(0, 2)
    ]

    TranslationFactory.create(
        locale=locale_a,
        entity=entities[0],
        approved=True,
        user=user_a,
    )
    TranslationFactory.create(
        locale=locale_a,
        entity=entities[1],
        fuzzy=True,
        user=user_a,
    )
    assert (
        list(Entity.for_project_locale(
            resource_a.project,
            locale_a,
            status='unreviewed',
            author=user_a.email,
        )) == []
    )
    assert (
        list(Entity.for_project_locale(
            resource_a.project,
            locale_a,
            status='unreviewed',
            time='201001010100-205001010100',
        )) == []
    )
开发者ID:Pike,项目名称:pontoon,代码行数:42,代码来源:test_entity.py

示例15: test_entity_project_locale_cleaned_key

# 需要导入模块: from pontoon.base.models import Entity [as 别名]
# 或者: from pontoon.base.models.Entity import for_project_locale [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


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