(**kwargs)
return data
Get or create a data object associated with a file.
Get or create a data object associated with a file.
Get or create a data object associated with a file .
def get_or_create(**kwargs):
    """
    Get or create a data object associated with a file.
    """
    fname = kwargs["file"]
    project = kwargs['project']
    uid = kwargs.get('uid')

    # Get the data if it exists.
    data = Data.objects.filter(uid=uid).first()

    if data and not data.deleted:
        create_data_link(path=fname, data=data)
        logger.info("Updated data file, name, and text.")
    else:
        # Create new data.
        data = create_data(project=project, path=fname, uid=uid, user=kwargs.get('user'))

    # Update the name, text, and type.
    data.name = kwargs.get('name') or data.name
    data.text = kwargs.get("text") or data.text
    data.type = kwargs.get("type", '').upper() or data.type or "DATA"

    # Trigger save to update the toc file, last edit date, etc.
    data.save()
    return data
def get_or_create ( * * kwargs ) : fname = kwargs [ "file" ] project = kwargs [ 'project' ] uid = kwargs . get ( 'uid' ) # Get the data if it exists. data = Data . objects . filter ( uid = uid ) . first ( ) if data and not data . deleted : create_data_link ( path = fname , data = data ) logger . info ( "Updated data file, name, and text." ) else : # Create new data. data = create_data ( project = project , path = fname , uid = uid , user = kwargs . get ( 'user' ) ) # Update the name, text, and type. data . name = kwargs . get ( 'name' ) or data . name data . text = kwargs . get ( "text" ) or data . text data . type = kwargs . get ( "type" , '' ) . upper ( ) or data . type or "DATA" # Trigger save to update the toc file, last edit date, etc. data . save ( ) return data