當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。