(data, project=None)
return field
Creates a DJANGO form field from a dictionary.
Creates a DJANGO form field from a dictionary.
Creates a DJANGO form field from a dictionary .
def dynamic_field(data, project=None):
    """
    Creates a DJANGO form field from a dictionary.
    """

    # Get the known field types.
    field_types = get_field_types(project=project)

    if not hasattr(data, 'get'):
        # Not a "dictionary-like" data
        return None

    # Find out the display type.
    display_type = data.get("display") or data.get('source')

    # Fields with no display type are not visible.
    if not display_type:
        return None

    # Data should be selected from a project or directrly from database.
    from_project = (data.get("source") == "PROJECT")
    if from_project and project:
        extras = data.get("choices", [])
        # Project specific data should have a type.
        data_type = data.get("type", "").strip() or ""

        if isinstance(data_type, dict):
            data_type = data_type.get("symbol", "").strip() or ""

        field = data_field_generator(data, project=project, type=data_type, extras=extras)

    else:
        # In all other cases we generate a field from the tuple.
        func = field_types.get(display_type)
        if not func:
            logger.error(f"Invalid display type={display_type}")
            return None
        field = func(data)

    return field
def dynamic_field ( data , project = None ) : # Get the known field types. field_types = get_field_types ( project = project ) if not hasattr ( data , 'get' ) : # Not a "dictionary-like" data return None # Find out the display type. display_type = data . get ( "display" ) or data . get ( 'source' ) # Fields with no display type are not visible. if not display_type : return None # Data should be selected from a project or directrly from database. from_project = ( data . get ( "source" ) == "PROJECT" ) if from_project and project : extras = data . get ( "choices" , [ ] ) # Project specific data should have a type. data_type = data . get ( "type" , "" ) . strip ( ) or "" if isinstance ( data_type , dict ) : data_type = data_type . get ( "symbol" , "" ) . strip ( ) or "" field = data_field_generator ( data , project = project , type = data_type , extras = extras ) else : # In all other cases we generate a field from the tuple. func = field_types . get ( display_type ) if not func : logger . error ( f"Invalid display type={display_type}" ) return None field = func ( data ) return field