(obj, user, data={}, stream=None, uid="", create=False, save=True)
return result
Update an existing project using data found in data dict.
Update an existing project using data found in data dict.
Update an existing project using data found in data dict .
def update_project(obj, user, data={}, stream=None, uid="", create=False, save=True):
    """
    Update an existing project using data found in data dict.
    """
    # Create a project when one does not exist.
    if not obj and create:
        obj = create_project(user=user, uid=uid)
    elif not obj:
        return

    try:
        data = data or json.load(stream)
    except Exception as exc:
        return {'error': f"Error loading json: {exc}"}

    # Set the project text and name.
    obj.text = data.get('text', obj.text)
    obj.name = data.get('name', obj.name)

    # Fetch the base64 image string and write to file.
    strimg = data.get('image')

    # Get the list of recipes
    recipes = data.get('recipes', [])

    if strimg:
        overwrite_image(obj=obj, strimg=strimg)

    if save:
        obj.save()

    # Iterate over and update recipes.
    for rec in recipes:
        recipe = Analysis.objects.filter(uid=rec['uid'], project=obj).first()
        update_recipe(obj=recipe, data=rec, save=True, project=obj, create=create, user=user)

    # Re-fetch updated data from the database.
    result = obj.api_data

    return result
def update_project ( obj , user , data = { } , stream = None , uid = "" , create = False , save = True ) : # Create a project when one does not exist. if not obj and create : obj = create_project ( user = user , uid = uid ) elif not obj : return try : data = data or json . load ( stream ) except Exception as exc : return { 'error' : f"Error loading json: {exc}" } # Set the project text and name. obj . text = data . get ( 'text' , obj . text ) obj . name = data . get ( 'name' , obj . name ) # Fetch the base64 image string and write to file. strimg = data . get ( 'image' ) # Get the list of recipes recipes = data . get ( 'recipes' , [ ] ) if strimg : overwrite_image ( obj = obj , strimg = strimg ) if save : obj . save ( ) # Iterate over and update recipes. for rec in recipes : recipe = Analysis . objects . filter ( uid = rec [ 'uid' ] , project = obj ) . first ( ) update_recipe ( obj = recipe , data = rec , save = True , project = obj , create = create , user = user ) # Re-fetch updated data from the database. result = obj . api_data return result