Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add items to portal sample #2135

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
" search_result = gis.content.search(query=file_name, item_type=current_item_type)\n",
nanaeaubry marked this conversation as resolved.
Show resolved Hide resolved
" if len(search_result) > 0:\n",
" for item in search_result:\n",
" item.delete()\n",
" item.delete(permanent=True) # if recycle bin is enabled, otherwise the parameter is ignored\n",
" print(\"Deleted existing \" + current_item_type + \": \", item)\n",
" \n",
"item_types = [\"Service Definition\", \"Feature Layer Collection\", \"Map Service\"]\n",
Expand Down Expand Up @@ -100,7 +100,8 @@
"source": [
"def delete_existing_folder(folder_name):\n",
" try:\n",
" return gis.content.delete_folder(folder=folder_name)\n",
" folder = gis.content.folders.get(folder_name)\n",
" return folder.delete(permanent=True) # if recycle bin is enabled, otherwise the parameter is ignored\n",
" except:\n",
" return False\n",
"\n",
Expand Down Expand Up @@ -204,9 +205,10 @@
}
],
"source": [
"root_folder = gis.content.folders.get()\n",
"# Loop through each file and publish it as a service\n",
"for current_sd_file in sd_file_list:\n",
" item = gis.content.add({}, data_dir + current_sd_file) # .sd file is uploaded and a .sd file item is created\n",
" item = root_folder.add({}, data_dir + current_sd_file) # .sd file is uploaded and a .sd file item is created\n",
" if \"BuildCache\" not in current_sd_file:\n",
" published_item = item.publish() # .sd file item is published and a web layer item is created\n",
" else:\n",
Expand Down Expand Up @@ -273,7 +275,8 @@
}
],
"source": [
"uploaded_file = p_gis.content.add({}, sd_file)\n",
"proot_folder = p_gis.content.folders.get()\n",
"uploaded_file = proot_folder.add({}, file=sd_file)\n",
"uploaded_file.tags"
]
},
Expand Down Expand Up @@ -364,8 +367,8 @@
}
],
"source": [
"item.delete()\n",
"uploaded_file.delete()"
"item.delete(permanent=True)\n",
"uploaded_file.delete(permanent=True)"
]
},
{
Expand All @@ -384,7 +387,7 @@
"outputs": [],
"source": [
"data = \"data/power_pedestals_2012.zip\"\n",
"shpfile = gis.content.add({}, data)"
"shpfile = root_folder.add({}, data)"
]
},
{
Expand Down Expand Up @@ -553,7 +556,7 @@
"outputs": [],
"source": [
"csv_file = 'data/Chennai_precipitation.csv'\n",
"csv_item = gis.content.add({}, csv_file)"
"csv_item = root_folder.add({}, csv_file)"
]
},
{
Expand Down Expand Up @@ -653,7 +656,7 @@
},
"source": [
"### Create a new folder for the items\n",
"The `create_folder()` from `GIS.content` can be used to create a new folder. Once created, the `move()` of the `Item` can be used to move the items into the folder."
"The `create()` from `GIS.content.folders` can be used to create a new folder. Once created, the `move()` of the `Item` can be used to move the items into the folder."
]
},
{
Expand All @@ -671,8 +674,8 @@
],
"source": [
"# create a new folder called 'Rainfall Data'\n",
"new_folder_details = gis.content.create_folder(my_folder_name)\n",
"print(new_folder_details)"
"new_folder = gis.content.folders.create(my_folder_name)\n",
"print(new_folder)"
]
},
{
Expand All @@ -696,10 +699,10 @@
],
"source": [
"# move both the csv_item and csv_lyr items into this new folder\n",
"csv_item.move(new_folder_details) # Here you could either pass name of the folder or the dictionary\n",
"csv_item.move(new_folder) # Here you could either pass name of the folder or the dictionary\n",
" # returned from create_folder() or folders property on a User object\n",
"\n",
"csv_lyr.move(new_folder_details)"
"csv_lyr.move(new_folder)"
]
},
{
Expand Down