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


Python ConceptVersion.get_latest_version_of方法代码示例

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


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

示例1: test_persist_clone_positive

# 需要导入模块: from concepts.models import ConceptVersion [as 别名]
# 或者: from concepts.models.ConceptVersion import get_latest_version_of [as 别名]
    def test_persist_clone_positive(self):
        self.assertEquals(2, self.concept1.num_versions)
        self.assertEquals(
            self.concept_version, ConceptVersion.get_latest_version_of(self.concept1))

        source_version = SourceVersion.get_latest_version_of(self.source1)

        source_version.update_concept_version(self.concept_version)
        self.assertEquals(1, len(source_version.concepts))
        self.assertEquals(self.concept_version.id, source_version.concepts[0])

        version2 = self.concept_version.clone()
        errors = ConceptVersion.persist_clone(version2, self.user1)
        self.assertEquals(0, len(errors))

        self.assertEquals(3, self.concept1.num_versions)
        self.assertEquals(version2, ConceptVersion.get_latest_version_of(self.concept1))
        self.assertEquals(self.concept_version.public_access, version2.public_access)
        self.assertEquals(self.concept_version, version2.previous_version)
        self.assertEquals(self.concept_version.root_version, version2.root_version)
        self.assertEquals(self.concept_version.external_id, version2.external_id)
        self.assertEquals(self.user1.username, version2.version_created_by)

        source_version.update_concept_version(version2)
        self.assertEquals(1, len(source_version.concepts))
        self.assertEquals(version2.id, source_version.concepts[0])
开发者ID:AnjaliWadhwa,项目名称:oclapi,代码行数:28,代码来源:tests.py

示例2: test_retire_positive

# 需要导入模块: from concepts.models import ConceptVersion [as 别名]
# 或者: from concepts.models.ConceptVersion import get_latest_version_of [as 别名]
    def test_retire_positive(self):
        source_version = SourceVersion.get_latest_version_of(self.source1)
        self.assertEquals(0, len(source_version.concepts))
        concept = Concept(
            mnemonic='concept1',
            created_by=self.user1,
            updated_by=self.user1,
            parent=self.source1,
            concept_class='First',
            names=[self.name],
        )
        kwargs = {
            'parent_resource': self.source1,
        }
        errors = Concept.persist_new(concept, self.user1, **kwargs)
        self.assertEquals(0, len(errors))
        self.assertTrue(Concept.objects.filter(mnemonic='concept1').exists())
        self.assertFalse(concept.retired)
        self.assertEquals(1, concept.num_versions)

        concept_version = ConceptVersion.get_latest_version_of(concept)
        self.assertTrue(concept_version.is_latest_version)
        self.assertFalse(concept_version.retired)

        source_version = SourceVersion.get_latest_version_of(self.source1)
        self.assertEquals(1, len(source_version.concepts))
        self.assertEquals(concept_version.id, source_version.concepts[0])

        errors = Concept.retire(concept, self.user1)
        self.assertFalse(errors)
        self.assertTrue(Concept.objects.filter(mnemonic='concept1').exists())
        self.assertTrue(concept.retired)
        self.assertEquals(2, concept.num_versions)

        previous_version = ConceptVersion.objects.get(id=concept_version.id)
        self.assertFalse(previous_version.is_latest_version)
        self.assertFalse(previous_version.retired)

        concept_version = ConceptVersion.get_latest_version_of(concept)
        self.assertTrue(concept_version.is_latest_version)
        self.assertTrue(concept_version.retired)
        self.assertEquals(self.user1.username, concept_version.version_created_by)

        source_version = SourceVersion.get_latest_version_of(self.source1)
        self.assertEquals(1, len(source_version.concepts))
        self.assertEquals(concept_version.id, source_version.concepts[0])

        self.assertEquals(
            1, ConceptVersion.objects.filter(versioned_object_id=concept.id, retired=True).count())
        self.assertEquals(
            1, ConceptVersion.objects.filter(versioned_object_id=concept.id, retired=False).count())

        errors = Concept.retire(concept, self.user1)
        self.assertEquals(1, len(errors))
开发者ID:AnjaliWadhwa,项目名称:oclapi,代码行数:56,代码来源:tests.py

示例3: setUp

# 需要导入模块: from concepts.models import ConceptVersion [as 别名]
# 或者: from concepts.models.ConceptVersion import get_latest_version_of [as 别名]
    def setUp(self):
        super(ConceptVersionStaticMethodsTest, self).setUp()
        self.concept1 = Concept(
            mnemonic='concept1', concept_class='First', public_access=ACCESS_TYPE_EDIT)
        display_name = LocalizedText(name='concept1', locale='en')
        self.concept1.names.append(display_name)
        kwargs = {
            'parent_resource': self.source1,
        }
        Concept.persist_new(self.concept1, self.user1, **kwargs)
        initial_version = ConceptVersion.get_latest_version_of(self.concept1)

        self.concept2 = Concept(mnemonic='concept2', concept_class='Second', names=[self.name])
        kwargs = {
            'parent_resource': self.source2,
        }
        Concept.persist_new(self.concept2, self.user1, **kwargs)

        self.concept_version = ConceptVersion(
            mnemonic='version1',
            versioned_object=self.concept1,
            concept_class='First',
            names=self.concept1.names,
            previous_version=initial_version,
            created_by=self.user1.username,
            updated_by=self.user1.username,
            version_created_by=self.user1.username,
        )
        self.concept_version.full_clean()
        self.concept_version.save()
开发者ID:AnjaliWadhwa,项目名称:oclapi,代码行数:32,代码来源:tests.py

示例4: test_create_concept_version_positive

# 需要导入模块: from concepts.models import ConceptVersion [as 别名]
# 或者: from concepts.models.ConceptVersion import get_latest_version_of [as 别名]
    def test_create_concept_version_positive(self):
        self.assertEquals(1, self.concept1.num_versions)
        concept_version = ConceptVersion(
            mnemonic='version1',
            versioned_object=self.concept1,
            concept_class='First',
            names=self.concept1.names,
            created_by=self.user1.username,
            updated_by=self.user1.username,
            version_created_by=self.user1.username,
        )
        concept_version.full_clean()
        concept_version.save()
        self.assertTrue(ConceptVersion.objects.filter(
            mnemonic='version1',
            versioned_object_type=ContentType.objects.get_for_model(Concept),
            versioned_object_id=self.concept1.id,
        ).exists())
        self.assertEquals(2, self.concept1.num_versions)
        self.assertEquals(concept_version, ConceptVersion.get_latest_version_of(self.concept1))

        self.assertEquals(self.concept1.mnemonic, concept_version.name)
        self.assertEquals(self.concept1.owner_name, concept_version.owner_name)
        self.assertEquals(self.concept1.owner_type, concept_version.owner_type)
        self.assertEquals(self.concept1.display_name, concept_version.display_name)
        self.assertEquals(self.concept1.display_locale, concept_version.display_locale)
开发者ID:AnjaliWadhwa,项目名称:oclapi,代码行数:28,代码来源:tests.py

示例5: resolve_reference

# 需要导入模块: from concepts.models import ConceptVersion [as 别名]
# 或者: from concepts.models.ConceptVersion import get_latest_version_of [as 别名]
 def resolve_reference(self, concept_reference):
     if concept_reference.concept_version:
         return concept_reference.concept_version
     elif concept_reference.source_version:
         concept_versions = ConceptVersion.objects.filter(id__in=concept_reference.source_version.concepts)
         return concept_versions.get(versioned_object_id=concept_reference.concept.id)
     return ConceptVersion.get_latest_version_of(concept_reference.concept)
开发者ID:AnjaliWadhwa,项目名称:oclapi,代码行数:9,代码来源:views.py

示例6: test_persist_new_positive

# 需要导入模块: from concepts.models import ConceptVersion [as 别名]
# 或者: from concepts.models.ConceptVersion import get_latest_version_of [as 别名]
    def test_persist_new_positive(self):
        concept = Concept(
            mnemonic='concept1',
            created_by=self.user1,
            parent=self.source1,
            concept_class='First',
            names=[self.name],
        )
        source_version = SourceVersion.get_latest_version_of(self.source1)
        self.assertEquals(0, len(source_version.concepts))
        kwargs = {
            'parent_resource': self.source1,
        }
        errors = Concept.persist_new(concept, self.user1, **kwargs)
        self.assertEquals(0, len(errors))

        self.assertTrue(Concept.objects.filter(mnemonic='concept1').exists())
        self.assertFalse(concept.retired)
        self.assertEquals(self.name.name, concept.display_name)
        self.assertEquals(self.name.locale, concept.display_locale)
        self.assertEquals(self.source1.owner_name, concept.owner_name)
        self.assertEquals(self.source1.owner_type, concept.owner_type)
        self.assertEquals(self.source1.public_access, concept.public_access)
        self.assertEquals(1, concept.num_versions)
        concept_version = ConceptVersion.get_latest_version_of(concept)
        self.assertEquals(concept_version, concept_version.root_version)

        source_version = SourceVersion.objects.get(id=source_version.id)
        self.assertEquals(1, len(source_version.concepts))
        self.assertTrue(concept_version.id in source_version.concepts)
        self.assertEquals(concept_version.mnemonic, concept_version.id)
开发者ID:AnjaliWadhwa,项目名称:oclapi,代码行数:33,代码来源:tests.py

示例7: update

# 需要导入模块: from concepts.models import ConceptVersion [as 别名]
# 或者: from concepts.models.ConceptVersion import get_latest_version_of [as 别名]
    def update(self, request, *args, **kwargs):
        self.permission_classes = (CanEditParentDictionary,)
        if hasattr(self.parent_resource, 'versioned_object'):
            parent_versioned_object = self.parent_resource.versioned_object
            if self.parent_resource != type(self.parent_resource).get_latest_version_of(parent_versioned_object):
                return Response({'non_field_errors': 'Parent version is not the latest.  Cannot update concept.'}, status=status.HTTP_400_BAD_REQUEST)

        self.serializer_class = ConceptVersionUpdateSerializer
        partial = kwargs.pop('partial', True)
        self.object = self.get_object_or_none()

        if self.object is None:
            return Response({'non_field_errors': 'Could not find concept to update'}, status=status.HTTP_404_NOT_FOUND)
        else:
            latest_version = ConceptVersion.get_latest_version_of(self.object)
            self.object = latest_version.clone()
            save_kwargs = {'force_update': False}
            success_status_code = status.HTTP_200_OK

        serializer = self.get_serializer(self.object, data=request.DATA,
                                         files=request.FILES, partial=partial)

        if serializer.is_valid():
            self.pre_save(serializer.object)
            self.object = serializer.save(**save_kwargs)
            if serializer.is_valid():
                self.post_save(self.object, created=True)
                serializer = ConceptVersionDetailSerializer(self.object, context={'request': request})
                return Response(serializer.data, status=success_status_code)

        return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
开发者ID:AnjaliWadhwa,项目名称:oclapi,代码行数:33,代码来源:views.py

示例8: test_concept_version_clone

# 需要导入模块: from concepts.models import ConceptVersion [as 别名]
# 或者: from concepts.models.ConceptVersion import get_latest_version_of [as 别名]
    def test_concept_version_clone(self):
        self.assertEquals(1, self.concept1.num_versions)
        concept_version = ConceptVersion(
            mnemonic='version1',
            versioned_object=self.concept1,
            concept_class='First',
            names=self.concept1.names,
            created_by=self.user1.username,
            updated_by=self.user1.username,
            version_created_by=self.user1.username,
        )
        concept_version.full_clean()
        concept_version.save()
        self.assertTrue(ConceptVersion.objects.filter(
            mnemonic='version1',
            versioned_object_type=ContentType.objects.get_for_model(Concept),
            versioned_object_id=self.concept1.id,
        ).exists())
        self.assertEquals(2, self.concept1.num_versions)
        self.assertEquals(concept_version, ConceptVersion.get_latest_version_of(self.concept1))

        self.assertEquals(self.concept1.mnemonic, concept_version.name)
        self.assertEquals(self.concept1.owner_name, concept_version.owner_name)
        self.assertEquals(self.concept1.owner_type, concept_version.owner_type)
        self.assertEquals(self.concept1.display_name, concept_version.display_name)
        self.assertEquals(self.concept1.display_locale, concept_version.display_locale)

        version2 = concept_version.clone()
        version2.mnemonic = 'version2'
        version2.created_by = self.user1.username
        version2.updated_by = self.user1.username
        version2.version_created_by = self.user1.username
        version2.full_clean()
        version2.save()

        self.assertEquals(3, self.concept1.num_versions)
        self.assertEquals(version2, ConceptVersion.get_latest_version_of(self.concept1))
        self.assertEquals(concept_version, version2.previous_version)
        self.assertEquals(concept_version.public_access, version2.public_access)

        self.assertEquals(self.concept1, version2.versioned_object)
        self.assertEquals(self.concept1.mnemonic, version2.name)
        self.assertEquals(self.concept1.owner_name, version2.owner_name)
        self.assertEquals(self.concept1.owner_type, version2.owner_type)
        self.assertEquals(self.concept1.display_name, version2.display_name)
        self.assertEquals(self.concept1.display_locale, version2.display_locale)
开发者ID:AnjaliWadhwa,项目名称:oclapi,代码行数:48,代码来源:tests.py

示例9: test_persist_clone_negative__no_user

# 需要导入模块: from concepts.models import ConceptVersion [as 别名]
# 或者: from concepts.models.ConceptVersion import get_latest_version_of [as 别名]
    def test_persist_clone_negative__no_user(self):
        self.assertEquals(2, self.concept1.num_versions)
        self.assertEquals(
            self.concept_version, ConceptVersion.get_latest_version_of(self.concept1))

        source_version = SourceVersion.get_latest_version_of(self.source1)

        source_version.update_concept_version(self.concept_version)
        self.assertEquals(1, len(source_version.concepts))
        self.assertEquals(self.concept_version.id, source_version.concepts[0])

        version2 = self.concept_version.clone()
        errors = ConceptVersion.persist_clone(version2)
        self.assertEquals(1, len(errors))
        self.assertTrue('version_created_by' in errors)

        self.assertEquals(2, self.concept1.num_versions)
        self.assertEquals(
            self.concept_version, ConceptVersion.get_latest_version_of(self.concept1))
开发者ID:AnjaliWadhwa,项目名称:oclapi,代码行数:21,代码来源:tests.py

示例10: get_object

# 需要导入模块: from concepts.models import ConceptVersion [as 别名]
# 或者: from concepts.models.ConceptVersion import get_latest_version_of [as 别名]
 def get_object(self, queryset=None):
     if self.versioned_object:
         concept_version_identifier = self.kwargs.get(self.lookup_field)
         if not concept_version_identifier:
             return ConceptVersion.get_latest_version_of(self.versioned_object)
         queryset = self.get_queryset()
         filter_kwargs = {'versioned_object_id': self.versioned_object.id,
                          self.pk_field: concept_version_identifier}
         return get_object_or_404(queryset, **filter_kwargs)
     return super(ConceptVersionRetrieveView, self).get_object()
开发者ID:AnjaliWadhwa,项目名称:oclapi,代码行数:12,代码来源:views.py

示例11: to_native

# 需要导入模块: from concepts.models import ConceptVersion [as 别名]
# 或者: from concepts.models.ConceptVersion import get_latest_version_of [as 别名]
 def to_native(self, obj):
     field = obj
     if isinstance(obj, ConceptReference):
         concept = obj.concept
         if obj.is_current_version:
             field = ConceptVersion.get_latest_version_of(concept)
         elif obj.source_version:
             field = ConceptVersion.objects.get(
                 versioned_object_id=concept.id, id__in=obj.source_version.concepts)
         else:
             field = obj.concept_version
     return super(ReferencesToVersionsSerializer, self).to_native(field)
开发者ID:AnjaliWadhwa,项目名称:oclapi,代码行数:14,代码来源:serializers.py

示例12: create

# 需要导入模块: from concepts.models import ConceptVersion [as 别名]
# 或者: from concepts.models.ConceptVersion import get_latest_version_of [as 别名]
    def create(self, request, *args, **kwargs):
        serializer = self.get_serializer(data=request.DATA, files=request.FILES)
        if serializer.is_valid():
            self.pre_save(serializer.object)
            save_kwargs = {
                'force_insert': True,
                'parent_resource': self.parent_resource
            }
            self.object = serializer.save(**save_kwargs)
            if serializer.is_valid():
                self.post_save(self.object, created=True)
                headers = self.get_success_headers(serializer.data)
                latest_version = ConceptVersion.get_latest_version_of(self.object)
                serializer = ConceptVersionDetailSerializer(latest_version)
                return Response(serializer.data, status=status.HTTP_201_CREATED,
                                headers=headers)

        return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
开发者ID:OpenConceptLab,项目名称:oclapi,代码行数:20,代码来源:views.py

示例13: update_concept_retired_status

# 需要导入模块: from concepts.models import ConceptVersion [as 别名]
# 或者: from concepts.models.ConceptVersion import get_latest_version_of [as 别名]
  def update_concept_retired_status(self, concept, new_retired_state):
      """ Updates and persists a new retired status for a concept """

      # Do nothing if retired status is unchanged
      concept_version = ConceptVersion.get_latest_version_of(concept)
      if concept_version.retired == new_retired_state:
          return ImportActionHelper.IMPORT_ACTION_NONE

      # Retire/un-retire the concept
      if new_retired_state:
          if not self.test_mode:
              errors = Concept.retire(concept, self.user)
              if errors:
                  raise IllegalInputException('Failed to retire concept due to %s' % errors)
          return ImportActionHelper.IMPORT_ACTION_RETIRE
      else:
          if not self.test_mode:
              errors = Concept.unretire(concept, self.user)
              if errors:
                  raise IllegalInputException('Failed to un-retire concept due to %s' % errors)
          return ImportActionHelper.IMPORT_ACTION_UNRETIRE
开发者ID:AnjaliWadhwa,项目名称:oclapi,代码行数:23,代码来源:importer.py

示例14: test_persist_new_positive__earlier_source_version

# 需要导入模块: from concepts.models import ConceptVersion [as 别名]
# 或者: from concepts.models.ConceptVersion import get_latest_version_of [as 别名]
    def test_persist_new_positive__earlier_source_version(self):
        version1 = SourceVersion.get_latest_version_of(self.source1)
        self.assertEquals(0, len(version1.concepts))
        version2 = SourceVersion.for_base_object(self.source1, label='version2')
        version2.save()
        self.assertEquals(0, len(version2.concepts))

        concept = Concept(
            mnemonic='concept1',
            created_by=self.user1,
            updated_by=self.user1,
            parent=self.source1,
            concept_class='First',
            names=[self.name],
        )
        kwargs = {
            'parent_resource': self.source1,
            'parent_resource_version': version1
        }
        errors = Concept.persist_new(concept, self.user1, **kwargs)
        self.assertEquals(0, len(errors))

        self.assertTrue(Concept.objects.filter(mnemonic='concept1').exists())
        self.assertFalse(concept.retired)
        self.assertEquals(self.name.name, concept.display_name)
        self.assertEquals(self.name.locale, concept.display_locale)
        self.assertEquals(self.source1.owner_name, concept.owner_name)
        self.assertEquals(self.source1.owner_type, concept.owner_type)
        self.assertEquals(self.source1.public_access, concept.public_access)
        self.assertEquals(1, concept.num_versions)
        concept_version = ConceptVersion.get_latest_version_of(concept)
        self.assertEquals(concept_version, concept_version.root_version)

        version1 = SourceVersion.objects.get(id=version1.id)
        self.assertEquals(1, len(version1.concepts))
        self.assertTrue(concept_version.id in version1.concepts)

        version2 = SourceVersion.objects.get(id=version2.id)
        self.assertEquals(0, len(version2.concepts))
        self.assertFalse(concept_version.id in version2.concepts)
开发者ID:AnjaliWadhwa,项目名称:oclapi,代码行数:42,代码来源:tests.py

示例15: item_description

# 需要导入模块: from concepts.models import ConceptVersion [as 别名]
# 或者: from concepts.models.ConceptVersion import get_latest_version_of [as 别名]
 def item_description(self, item):
     item = ConceptVersion.get_latest_version_of(item)
     return item.update_comment
开发者ID:AnjaliWadhwa,项目名称:oclapi,代码行数:5,代码来源:feeds.py


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