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


Python models.ConceptVersion类代码示例

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


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

示例1: test_persist_clone_positive

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

示例2: setUp

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

示例3: test_create_concept_version_negative__no_concept_class

 def test_create_concept_version_negative__no_concept_class(self):
     with self.assertRaises(ValidationError):
         concept_version = ConceptVersion(
             mnemonic='version1',
             versioned_object=self.concept1,
             names=[self.name],
         )
         concept_version.full_clean()
         concept_version.save()
开发者ID:AnjaliWadhwa,项目名称:oclapi,代码行数:9,代码来源:tests.py

示例4: test_retire_positive

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

示例5: resolve_reference

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

示例6: test_persist_new_positive

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

示例7: update

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

示例8: update_concept_version

  def update_concept_version(self, concept_version, data):
      """ Updates the concept, or skips if no diff. Ignores retired status. """

      # Generate the diff
      clone = concept_version.clone()
      serializer = ConceptVersionUpdateSerializer(
          clone, data=data, context={'request': MockRequest(self.user)})
      if not serializer.is_valid():
          raise IllegalInputException(
              'Could not parse concept to update: %s.' % concept_version.mnemonic)
      new_version = serializer.object
      diffs = ConceptVersion.diff(concept_version, new_version)

      # Update concept if different
      if diffs:
          if 'names' in diffs:
              diffs['names'] = {'is': data.get('names')}
          if 'descriptions' in diffs:
              diffs['descriptions'] = {'is': data.get('descriptions')}
          clone.update_comment = json.dumps(diffs)
          if not self.test_mode:
              serializer.save()
              if not serializer.is_valid():
                  raise IllegalInputException(
                      'Could not persist update to concept: %s' % concept_version.mnemonic)
          return ImportActionHelper.IMPORT_ACTION_UPDATE

      # No diff, so do nothing
      return ImportActionHelper.IMPORT_ACTION_NONE
开发者ID:AnjaliWadhwa,项目名称:oclapi,代码行数:29,代码来源:importer.py

示例9: delete

 def delete(self, request, *args, **kwargs):
     if self.key in self.extras:
         del self.extras[self.key]
         self.parent_resource_version.update_comment = 'Deleted extra %s.' % self.key
         errors = ConceptVersion.persist_clone(self.parent_resource_version, request.user)
         if errors:
             return Response(errors, status=status.HTTP_400_BAD_REQUEST)
         return Response(status=status.HTTP_204_NO_CONTENT)
     return Response({"detail": "Not found."}, status.HTTP_404_NOT_FOUND)
开发者ID:AnjaliWadhwa,项目名称:oclapi,代码行数:9,代码来源:views.py

示例10: test_add_duplicate_concept_reference_different_version_number

    def test_add_duplicate_concept_reference_different_version_number(self):
        source_with_open_mrs, user = self.create_source_and_user_fixture()
        collection = create_collection(user, CUSTOM_VALIDATION_SCHEMA_OPENMRS)

        (concept_one, errors) = create_concept(mnemonic="ConceptOne", user=self.user1, source=source_with_open_mrs, names=[
            create_localized_text(name='UserOne', locale='es', type='FULLY_SPECIFIED')])

        data = json.dumps({
            'data': {
                'expressions': [concept_one.url]
            }
        })

        kwargs = {'user': user.username, 'collection': collection.name}

        self.client.put(reverse('collection-references', kwargs=kwargs), data,
                        content_type='application/json')

        concept_version = ConceptVersion(
            mnemonic='version1',
            versioned_object=concept_one,
            concept_class='Diagnosis',
            datatype=concept_one.datatype,
            names=concept_one.names,
            created_by=self.user1.username,
            updated_by=self.user1.username,
            version_created_by=self.user1.username,
            descriptions=[create_localized_text("aDescription")])

        concept_version.full_clean()
        concept_version.save()

        data = json.dumps({
            'data': {
                'expressions': [concept_version.url]
            }
        })

        response = self.client.put(reverse('collection-references', kwargs=kwargs), data,
                                   content_type='application/json')

        self.assertEquals(response.status_code, status.HTTP_200_OK)
        self.assertEquals(response.data, [{'added': False, 'expression': concept_version.url,
                                           'message': [REFERENCE_ALREADY_EXISTS]}])
开发者ID:OpenConceptLab,项目名称:oclapi,代码行数:44,代码来源:collection_reference_validation.py

示例11: get_object

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

示例12: test_persist_clone_negative__no_user

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

示例13: to_native

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

示例14: test_create_concept_version_positive

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

示例15: test_concept_version_inherits_public_access__positive

    def test_concept_version_inherits_public_access__positive(self):
        public_access = self.source1.public_access
        self.assertEquals(1, self.concept1.num_versions)
        concept_version = ConceptVersion(
            mnemonic='version1',
            versioned_object=self.concept1,
            concept_class='First',
            public_access=public_access,
            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.assertEquals(self.source1.public_access, concept_version.public_access)
        self.source1.public_access = ACCESS_TYPE_VIEW
        self.source1.save()

        self.assertNotEquals(public_access, self.source1.public_access)
        concept_version = ConceptVersion.objects.get(id=concept_version.id)
        self.assertEquals(self.source1.public_access, concept_version.public_access)
开发者ID:AnjaliWadhwa,项目名称:oclapi,代码行数:23,代码来源:tests.py


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