(commcare_user, domain)
Updates demo restore for the demo commcare_user
Updates demo restore for the demo commcare_user
Updates demo restore for the demo commcare_user
def reset_demo_user_restore(commcare_user, domain):
    """
    Updates demo restore for the demo commcare_user
    """
    assert commcare_user.domain == domain

    # if there is a restore already, delete it
    delete_demo_restore_for_user(commcare_user)
    # get latest restore
    restore = RestoreConfig(
        project=Domain.get_by_name(domain),
        restore_user=commcare_user.to_ota_restore_user(),
        params=RestoreParams(version=V2),
    ).get_payload().as_file()
    demo_restore = DemoUserRestore.create(commcare_user._id, restore, domain)

    # Set reference to new restore
    try:
        commcare_user.demo_restore_id = demo_restore.id
        commcare_user.save()
    except ResourceConflict:
        # If CommCareUser.report_metadata gets updated by sync log pillow, after a restore is
        #   generated or for any other reason, there will be a DocumentUpdate conflict
        commcare_user = CommCareUser.get(commcare_user.get_id)
        commcare_user.is_demo_user = True
        commcare_user.demo_restore_id = demo_restore.id
        commcare_user.save()
def reset_demo_user_restore ( commcare_user , domain ) : assert commcare_user . domain == domain # if there is a restore already, delete it delete_demo_restore_for_user ( commcare_user ) # get latest restore restore = RestoreConfig ( project = Domain . get_by_name ( domain ) , restore_user = commcare_user . to_ota_restore_user ( ) , params = RestoreParams ( version = V2 ) , ) . get_payload ( ) . as_file ( ) demo_restore = DemoUserRestore . create ( commcare_user . _id , restore , domain ) # Set reference to new restore try : commcare_user . demo_restore_id = demo_restore . id commcare_user . save ( ) except ResourceConflict : # If CommCareUser.report_metadata gets updated by sync log pillow, after a restore is #   generated or for any other reason, there will be a DocumentUpdate conflict commcare_user = CommCareUser . get ( commcare_user . get_id ) commcare_user . is_demo_user = True commcare_user . demo_restore_id = demo_restore . id commcare_user . save ( )