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


Python models.Entity类代码示例

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


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

示例1: test_entity_project_locale_order

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,代码行数:26,代码来源:test_entity.py

示例2: test_entity_project_locale_subpages

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,代码行数:25,代码来源:test_entity.py

示例3: save_entity

def save_entity(resource, string, string_plural="", comment="",
                key="", source=""):
    """Admin interface: save new or update existing entity in DB."""

    # Update existing entity
    try:
        if key is "":
            e = Entity.objects.get(
                resource=resource, string=string,
                string_plural=string_plural)

        else:
            e = Entity.objects.get(resource=resource, key=key)
            e.string = string
            e.string_plural = string_plural

        e.source = source

        # Set obsolete attribute for all updated entities to False
        e.obsolete = False

    # Add new entity
    except Entity.DoesNotExist:
        e = Entity(resource=resource, string=string,
                   string_plural=string_plural, key=key, source=source)

    if len(comment) > 0:
        e.comment = comment

    e.save()
开发者ID:Acidburn0zzz,项目名称:pontoon,代码行数:30,代码来源:files.py

示例4: test_for_project_locale_filter

 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,代码行数:13,代码来源:test_models.py

示例5: test_entity_project_locale_filter

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,代码行数:16,代码来源:test_entity.py

示例6: entities

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,代码行数:34,代码来源:views.py

示例7: entities

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,代码行数:28,代码来源:views.py

示例8: entities

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,代码行数:34,代码来源:views.py

示例9: execute_create_db

    def execute_create_db(self):
        for vcs_entity in self.changes['create_db']:
            entity = Entity(**self.get_entity_updates(vcs_entity))
            entity.save()  # We can't use bulk_create since we need a PK

            for locale_code, vcs_translation in vcs_entity.translations.items():
                for plural_form, string in vcs_translation.strings.items():
                    self.translations_to_create.append(Translation(
                        entity=entity,
                        locale=self.locales[locale_code],
                        string=string,
                        plural_form=plural_form,
                        approved=not vcs_translation.fuzzy,
                        approved_date=self.now if not vcs_translation.fuzzy else None,
                        fuzzy=vcs_translation.fuzzy
                    ))
开发者ID:riseofthetigers,项目名称:pontoon,代码行数:16,代码来源:sync_projects.py

示例10: test_entity_project_locale_tags

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,代码行数:17,代码来源:test_entity.py

示例11: test_entity_project_locale_cleaned_key

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,代码行数:17,代码来源:test_entity.py

示例12: test_for_project_locale_cleaned_key

    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,代码行数:9,代码来源:test_models.py

示例13: test_for_project_locale_plurals

    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,代码行数:10,代码来源:test_models.py

示例14: test_for_project_locale_order

    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,代码行数:10,代码来源:test_models.py

示例15: test_for_project_locale_paths

    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,代码行数:10,代码来源:test_models.py


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