mongoframes/frames.py
def _flatten_projection(cls, projection):
        """
        Flatten a structured projection (structure projections support for
        projections of (to be) dereferenced fields.
        """

        # If `projection` is empty return a full projection based on `_fields`
        if not projection:
            return {f: True for f in cls._fields}, {}, {}

        # Flatten the projection
        flat_projection = {}
        references = {}
        subs = {}
        inclusive = True
        for key, value in deepcopy(projection).items():
            if isinstance(value, dict):

                # Build the projection value for the field (allowing for
                # special mongo directives).
                project_value = {
                    k: v for k, v in value.items()
                    if k.startswith('$') and k not in ['$ref', '$sub', '$sub.']
                }
                if len(project_value) == 0:
                    project_value = True
                else:
                    project_value = {key: project_value}
                    inclusive = False

                # Store a reference/sub-frame projection
                if '$ref' in value:
                    references[key] = value

                elif '$sub' in value or '$sub.' in value:
                    subs[key] = value

                    if '$sub' in value:
                        sub_frame = value['$sub']

                    if '$sub.' in value:
                        sub_frame = value['$sub.']

                    project_value = sub_frame._projection_to_paths(key, value)

                if isinstance(project_value, dict):
                    flat_projection.update(project_value)

                else:
                    flat_projection[key] = project_value

            elif key == '$ref':
                # Strip any $ref key
                continue

            elif key == '$sub' or key == '$sub.':
                # Strip any $sub key
                continue

            elif key.startswith('$'):
                # Strip mongo operators
                continue

            else:
                # Store the root projection value
                flat_projection[key] = value
                inclusive = False

        # If only references and sub-frames where specified in the projection
        # then return a full projection based on `_fields`.
        if inclusive:
            flat_projection = {f: True for f in cls._fields}

        return flat_projection, references, subs

        Flatten a structured projection (structure projections support for
        projections of (to be) dereferenced fields.
        
Flatten a structured projection (structure projections support for
projections of (to be) dereferenced fields.
Flatten a structured projection ( structure projections support for projections of ( to be ) dereferenced fields .
def _flatten_projection(cls, projection):
        if not projection:
            return {f: True for f in cls._fields}, {}, {}
        flat_projection = {}
        references = {}
        subs = {}
        inclusive = True
        for key, value in deepcopy(projection).items():
            if isinstance(value, dict):
                project_value = {
                    k: v for k, v in value.items()
                    if k.startswith('$') and k not in ['$ref', '$sub', '$sub.']
                }
                if len(project_value) == 0:
                    project_value = True
                else:
                    project_value = {key: project_value}
                    inclusive = False
                if '$ref' in value:
                    references[key] = value
                elif '$sub' in value or '$sub.' in value:
                    subs[key] = value
                    if '$sub' in value:
                        sub_frame = value['$sub']
                    if '$sub.' in value:
                        sub_frame = value['$sub.']
                    project_value = sub_frame._projection_to_paths(key, value)
                if isinstance(project_value, dict):
                    flat_projection.update(project_value)
                else:
                    flat_projection[key] = project_value
            elif key == '$ref':
                continue
            elif key == '$sub' or key == '$sub.':
                continue
            elif key.startswith('$'):
                continue
            else:
                flat_projection[key] = value
                inclusive = False
        if inclusive:
            flat_projection = {f: True for f in cls._fields}
        return flat_projection, references, subs
def _flatten_projection ( cls , projection ) : if not projection : return { f : True for f in cls . _fields } , { } , { } flat_projection = { } references = { } subs = { } inclusive = True for key , value in deepcopy ( projection ) . items ( ) : if isinstance ( value , dict ) : project_value = { k : v for k , v in value . items ( ) if k . startswith ( '$' ) and k not in [ '$ref' , '$sub' , '$sub.' ] } if len ( project_value ) == 0 : project_value = True else : project_value = { key : project_value } inclusive = False if '$ref' in value : references [ key ] = value elif '$sub' in value or '$sub.' in value : subs [ key ] = value if '$sub' in value : sub_frame = value [ '$sub' ] if '$sub.' in value : sub_frame = value [ '$sub.' ] project_value = sub_frame . _projection_to_paths ( key , value ) if isinstance ( project_value , dict ) : flat_projection . update ( project_value ) else : flat_projection [ key ] = project_value elif key == '$ref' : continue elif key == '$sub' or key == '$sub.' : continue elif key . startswith ( '$' ) : continue else : flat_projection [ key ] = value inclusive = False if inclusive : flat_projection = { f : True for f in cls . _fields } return flat_projection , references , subs
Flatten a structured projection (structure projections support for
projections of (to be) dereferenced fields.
Flatten a structured projection ( structure projections support for projections of ( to be ) dereferenced fields .
"""
        Flatten a structured projection (structure projections support for
        projections of (to be) dereferenced fields.
        """ # If `projection` is empty return a full projection based on `_fields` # Flatten the projection # Build the projection value for the field (allowing for # special mongo directives). # Store a reference/sub-frame projection # Strip any $ref key # Strip any $sub key # Strip mongo operators # Store the root projection value # If only references and sub-frames where specified in the projection # then return a full projection based on `_fields`.
cls
projection