Skip to content

Commit

Permalink
Concept/Mapping listings can ask for extras inclusions in response
Browse files Browse the repository at this point in the history
  • Loading branch information
snyaggarwal committed Feb 23, 2021
1 parent 8628334 commit 8b98353
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 15 deletions.
11 changes: 9 additions & 2 deletions core/concepts/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
UUIDField
from rest_framework.serializers import ModelSerializer

from core.common.constants import INCLUDE_INVERSE_MAPPINGS_PARAM, INCLUDE_MAPPINGS_PARAM
from core.common.constants import INCLUDE_INVERSE_MAPPINGS_PARAM, INCLUDE_MAPPINGS_PARAM, INCLUDE_EXTRAS_PARAM
from core.concepts.models import Concept, LocalizedText


Expand Down Expand Up @@ -113,6 +113,13 @@ def __init__(self, *args, **kwargs):
self.query_params = params.dict() if params else dict()
self.include_indirect_mappings = self.query_params.get(INCLUDE_INVERSE_MAPPINGS_PARAM) in ['true', True]
self.include_direct_mappings = self.query_params.get(INCLUDE_MAPPINGS_PARAM) in ['true', True]
self.include_extras = self.query_params.get(INCLUDE_EXTRAS_PARAM) in ['true', True]

try:
if not self.include_extras:
self.fields.pop('extras', None)
except: # pylint: disable=bare-except
pass

super().__init__(*args, **kwargs)

Expand All @@ -122,7 +129,7 @@ class Meta:
'uuid', 'id', 'external_id', 'concept_class', 'datatype', 'url', 'retired', 'source',
'owner', 'owner_type', 'owner_url', 'display_name', 'display_locale', 'version', 'update_comment',
'locale', 'version_created_by', 'version_created_on', 'mappings', 'is_latest_version', 'versions_url',
'version_url',
'version_url', 'extras',
)

@staticmethod
Expand Down
25 changes: 12 additions & 13 deletions core/mappings/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from rest_framework.serializers import ModelSerializer

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
MAPPING_LOOKUP_TO_CONCEPT, MAPPING_LOOKUP_FROM_SOURCE, MAPPING_LOOKUP_TO_SOURCE, INCLUDE_EXTRAS_PARAM
from core.concepts.serializers import ConceptListSerializer, ConceptDetailSerializer
from core.mappings.models import Mapping
from core.sources.serializers import SourceListSerializer, SourceDetailSerializer
Expand Down Expand Up @@ -36,26 +36,20 @@ class Meta:
'url', 'version', 'id', 'versioned_object_id', 'versioned_object_url',
'is_latest_version', 'update_comment', 'version_url', 'uuid', 'version_created_on',
'from_source_version', 'to_source_version', 'from_concept', 'to_concept', 'from_source', 'to_source',
'from_concept_name_resolved', 'to_concept_name_resolved'
'from_concept_name_resolved', 'to_concept_name_resolved', 'extras',
)

def __init__(self, *args, **kwargs):
params = get(kwargs, 'context.request.query_params')
self.query_params = params.dict() if params else dict()
self.include_from_source = False
self.include_to_source = False
self.include_sources = False
self.include_from_concept = False
self.include_to_concept = False
self.include_concepts = False

self.include_concepts = self.query_params.get(MAPPING_LOOKUP_CONCEPTS) in ['true', True]
self.include_from_source = self.query_params.get(MAPPING_LOOKUP_FROM_SOURCE) in ['true', True]
self.include_to_source = self.query_params.get(MAPPING_LOOKUP_TO_SOURCE) in ['true', True]
self.include_sources = self.query_params.get(MAPPING_LOOKUP_SOURCES) in ['true', True]
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_sources = self.query_params.get(MAPPING_LOOKUP_SOURCES) in ['true', True]
self.include_from_source = self.query_params.get(MAPPING_LOOKUP_FROM_SOURCE) in ['true', True]
self.include_to_source = self.query_params.get(MAPPING_LOOKUP_TO_SOURCE) in ['true', True]
self.include_extras = self.query_params.get(INCLUDE_EXTRAS_PARAM) in ['true', True]

if not self.include_concepts:
if not self.include_from_concept:
Expand All @@ -69,6 +63,11 @@ def __init__(self, *args, **kwargs):
if not self.include_to_source:
self.fields.pop('to_source')

if not self.include_extras and self.__class__.__name__ in [
'MappingListSerializer', 'MappingVersionListSerializer'
]:
self.fields.pop('extras', None)

super().__init__(*args, **kwargs)


Expand Down

0 comments on commit 8b98353

Please sign in to comment.