Skip to content

Commit

Permalink
OpenConceptLab/ocl_issues#1280 | added verbose references in collecti…
Browse files Browse the repository at this point in the history
…on's concept/mapping responses via query param
  • Loading branch information
snyaggarwal committed Apr 21, 2022
1 parent 75f8f3e commit e095cad
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
1 change: 1 addition & 0 deletions core/common/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
INCLUDE_CREATOR_PINS = 'includeCreatorPins'
INCLUDE_HIERARCHY_ROOT = 'includeHierarchyRoot'
INCLUDE_SUMMARY = 'includeSummary'
INCLUDE_VERBOSE_REFERENCES = 'includeReferences'
INCLUDE_VERIFICATION_TOKEN = 'includeVerificationToken'
INCLUDE_AUTH_GROUPS = 'includeAuthGroups'
INCLUDE_INACTIVE = 'includeInactive'
Expand Down
8 changes: 5 additions & 3 deletions core/common/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -583,9 +583,11 @@ def save(self, force_insert=False, force_update=False, using=None, update_fields
return result

def collection_references_uris(self, collection):
uri = collection.uri
ids = self.references.filter(collection=collection).values_list('id', flat=True)
return [f"{uri}references/{_id}/" for _id in ids]
ids = self.collection_references(collection).values_list('id', flat=True)
return [f"{collection.uri}references/{_id}/" for _id in ids]

def collection_references(self, collection):
return self.references.filter(collection=collection)


class ConceptContainerExportMixin:
Expand Down
6 changes: 5 additions & 1 deletion core/concepts/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from core.common.constants import INCLUDE_INVERSE_MAPPINGS_PARAM, INCLUDE_MAPPINGS_PARAM, INCLUDE_EXTRAS_PARAM, \
INCLUDE_PARENT_CONCEPTS, INCLUDE_CHILD_CONCEPTS, INCLUDE_SOURCE_VERSIONS, INCLUDE_COLLECTION_VERSIONS, \
CREATE_PARENT_VERSION_QUERY_PARAM, INCLUDE_HIERARCHY_PATH, INCLUDE_PARENT_CONCEPT_URLS, \
INCLUDE_CHILD_CONCEPT_URLS, HEAD, INCLUDE_SUMMARY
INCLUDE_CHILD_CONCEPT_URLS, HEAD, INCLUDE_SUMMARY, INCLUDE_VERBOSE_REFERENCES
from core.common.fields import EncodedDecodedCharField
from core.common.utils import to_parent_uri_from_kwargs
from core.concepts.models import Concept, LocalizedText
Expand Down Expand Up @@ -135,6 +135,7 @@ def __init__(self, *args, **kwargs): # pylint: disable=too-many-branches
self.include_hierarchy_path = self.query_params.get(INCLUDE_HIERARCHY_PATH) in ['true', True]
self.include_extras = self.query_params.get(INCLUDE_EXTRAS_PARAM) in ['true', True]
self.include_summary = self.query_params.get(INCLUDE_SUMMARY) in ['true', True]
self.include_verbose_references = self.query_params.get(INCLUDE_VERBOSE_REFERENCES) in ['true', True]
if CREATE_PARENT_VERSION_QUERY_PARAM in self.query_params:
self.create_parent_version = self.query_params.get(CREATE_PARENT_VERSION_QUERY_PARAM) in ['true', True]
else:
Expand Down Expand Up @@ -171,6 +172,9 @@ def __init__(self, *args, **kwargs): # pylint: disable=too-many-branches
def get_references(self, obj):
collection = get(self, 'context.request.instance')
if collection:
if self.include_verbose_references:
from core.collections.serializers import CollectionReferenceSerializer
return CollectionReferenceSerializer(obj.collection_references(collection), many=True).data
return obj.collection_references_uris(collection)
return None

Expand Down
7 changes: 5 additions & 2 deletions core/mappings/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from core.common.constants import MAPPING_LOOKUP_CONCEPTS, MAPPING_LOOKUP_SOURCES, MAPPING_LOOKUP_FROM_CONCEPT, \
MAPPING_LOOKUP_TO_CONCEPT, MAPPING_LOOKUP_FROM_SOURCE, MAPPING_LOOKUP_TO_SOURCE, INCLUDE_EXTRAS_PARAM, \
INCLUDE_SOURCE_VERSIONS, INCLUDE_COLLECTION_VERSIONS
INCLUDE_SOURCE_VERSIONS, INCLUDE_COLLECTION_VERSIONS, INCLUDE_VERBOSE_REFERENCES
from core.common.fields import EncodedDecodedCharField
from core.concepts.serializers import ConceptListSerializer, ConceptDetailSerializer
from core.mappings.models import Mapping
Expand Down Expand Up @@ -55,8 +55,8 @@ def __init__(self, *args, **kwargs):
self.include_from_concept = self.query_params.get(MAPPING_LOOKUP_FROM_CONCEPT) in ['true', True]
self.include_to_concept = self.query_params.get(MAPPING_LOOKUP_TO_CONCEPT) in ['true', True]
self.include_concepts = self.query_params.get(MAPPING_LOOKUP_CONCEPTS) in ['true', True]

self.include_extras = self.query_params.get(INCLUDE_EXTRAS_PARAM) in ['true', True]
self.include_verbose_references = self.query_params.get(INCLUDE_VERBOSE_REFERENCES) in ['true', True]

if not self.include_concepts:
if not self.include_from_concept:
Expand All @@ -83,6 +83,9 @@ def __init__(self, *args, **kwargs):
def get_references(self, obj):
collection = get(self, 'context.request.instance')
if collection:
if self.include_verbose_references:
from core.collections.serializers import CollectionReferenceSerializer
return CollectionReferenceSerializer(obj.collection_references(collection), many=True).data
return obj.collection_references_uris(collection)
return None

Expand Down

0 comments on commit e095cad

Please sign in to comment.