コード例 #1
0
    def delete(self, **kwargs):
        resource_used_message = '''Source %s cannot be deleted because others have created mapping or references that point to it.
                To delete this source, you must first delete all linked mappings and references.''' % self.uri

        from concepts.models import Concept
        concepts = Concept.objects.filter(parent_id=self.id)
        from mappings.models import Mapping
        mappings = Mapping.objects.filter(parent_id=self.id)

        concept_ids = [c.id for c in concepts]
        mapping_ids = [m.id for m in mappings]

        from concepts.models import ConceptVersion
        concept_versions = ConceptVersion.objects.filter(
            versioned_object_id__in=concept_ids)
        from mappings.models import MappingVersion
        mapping_versions = MappingVersion.objects.filter(
            versioned_object_id__in=mapping_ids)

        concept_version_ids = [c.id for c in concept_versions]
        mapping_version_ids = [m.id for m in mapping_versions]

        # Check if concepts from this source are in any collection
        from collection.models import CollectionVersion
        collections = CollectionVersion.get_collection_versions_with_concepts(
            concept_version_ids)

        usage_summary = ''
        if collections:
            usage_summary = ' Concepts in collections: ' + self.join_uris(
                collections) + ';'

        # Check if mappings from this source are in any collection
        collections = CollectionVersion.get_collection_versions_with_mappings(
            mapping_version_ids)
        if collections:
            usage_summary = usage_summary + ' Mappings in collections: ' + self.join_uris(
                collections) + ';'

        # Check if mappings from this source are referred in any sources
        mapping_versions = MappingVersion.objects.filter(
            Q(to_concept_id__in=concept_ids)
            | Q(from_concept_id__in=concept_ids)).exclude(parent_id=self.id)
        if mapping_versions:
            usage_summary = usage_summary + ' Mappings: ' + self.join_uris(
                mapping_versions) + ';'

        if usage_summary:
            raise Exception(resource_used_message + usage_summary)

        RawQueries().delete_source(self)
コード例 #2
0
ファイル: models.py プロジェクト: OpenConceptLab/oclapi
    def delete(self, **kwargs):
        resource_used_message = '''Source %s cannot be deleted because others have created mapping or references that point to it.
                To delete this source, you must first delete all linked mappings and references.''' % self.uri

        from concepts.models import Concept
        concepts = Concept.objects.filter(parent_id=self.id)
        from mappings.models import Mapping
        mappings = Mapping.objects.filter(parent_id=self.id)

        concept_ids = [c.id for c in concepts]
        mapping_ids = [m.id for m in mappings]

        from concepts.models import ConceptVersion
        concept_versions = ConceptVersion.objects.filter(
            versioned_object_id__in=concept_ids
        )
        from mappings.models import MappingVersion
        mapping_versions = MappingVersion.objects.filter(
            versioned_object_id__in=mapping_ids
        )

        concept_version_ids = [c.id for c in concept_versions]
        mapping_version_ids = [m.id for m in mapping_versions]

        # Check if concepts from this source are in any collection
        from collection.models import CollectionVersion
        collections = CollectionVersion.get_collection_versions_with_concepts(concept_version_ids)

        usage_summary = ''
        if collections:
            usage_summary = ' Concepts in collections: ' + self.join_uris(collections) + ';'

        # Check if mappings from this source are in any collection
        collections = CollectionVersion.get_collection_versions_with_mappings(mapping_version_ids)
        if collections:
            usage_summary = usage_summary + ' Mappings in collections: ' + self.join_uris(collections) + ';'

        # Check if mappings from this source are referred in any sources
        mapping_versions = MappingVersion.objects.filter(
            Q(to_concept_id__in=concept_ids) | Q(from_concept_id__in=concept_ids)
        ).exclude(parent_id=self.id)
        if mapping_versions:
            usage_summary = usage_summary + ' Mappings: ' + self.join_uris(mapping_versions) + ';'

        if usage_summary:
            raise Exception(resource_used_message + usage_summary)

        RawQueries().delete_source(self)