Hi,
Is there a way to reset the gis.users.categories? Or update / remove specific entries in the memberCategorySchema?
gis.users.categories = None
will delet all the user-categories, but reloading a memberCategorySchema will fail afterwards.
gis.users.categories = {'memberCategorySchema': [
{'title': 'Categories','categories': [{'title': 'bla','categories': [{'title': 'bli','categories': [{'title': 'blu'}]}]}]}]}
self._gis.users.categories[0]["categories"]
IndexError: list index out of range
Solved! Go to Solution.
What error are you getting? It it this...
ValueError: A list or tuple must be given to set the categories.
I get this error if the categories is already set to None. Worked around it with the below.
from arcgis.gis import GIS
agol = GIS("home")
## only update to None if it is not already None
if agol.users.categories != None:
agol.users.categories = None
user_schema = {
'memberCategorySchema': [
{
'title': 'Categories',
'categories': [
{
'title': 'bla',
'categories': [
{
'title': 'bli',
'categories': [
{
'title': 'blu'
}
]
}
]
}
]
}
]
}
agol.users.categories = user_schema
print(agol.users.categories)
Hey Andreas have you tried using gis.content.categories.delete()?
Based on the documentation you may need to fully remove the the category schema, remake and reassign this.
Hope that helps,
David
Hi,
Thanks for the reply.
Your answer refers to content-categories... I'm talking about user-categories and the "memberCategorySchema". There is no gis.users.categories.delete()...
I am using arcgis api version 2.2.0.1 and I have no issue with the following.
Create a user category schema
from arcgis.gis import GIS
agol = GIS("home")
user_schema = {
"memberCategorySchema": [
{
"title": "Office Location",
"categories": [
{
"title": "USA",
"categories": [
{
"title": "Maine"
},
{
"title": "California",
"categories": [
{
"title": "Redlands"
},
{
"title": "San Diego"
}
]
}
]
},
{
"title": "Europe",
"categories": [
{
"title": "Zurich"
},
{
"title": "Edinburgh"
}
]
}
]
},
{
"title": "Department",
"categories": [
{
"title": "Sales"
},
{
"title": "Consulting"
}
]
}
]
}
agol.users.categories = user_schema
Print to test... I wont add results put it prints fine
from arcgis.gis import GIS
agol = GIS("home")
print(agol.users.categories)
Delete the schema
from arcgis.gis import GIS
agol = GIS("home")
agol.users.categories = None
Re-print, it returns None.
Re-assign a new schema.
from arcgis.gis import GIS
agol = GIS("home")
user_schema = {
'memberCategorySchema': [
{
'title': 'Categories',
'categories': [
{
'title': 'bla',
'categories': [
{
'title': 'bli',
'categories': [
{
'title': 'blu'
}
]
}
]
}
]
}
]
}
agol.users.categories = user_schema
Printing new schema works just fine.
from arcgis.gis import GIS
agol = GIS("home")
print(agol.users.categories[0]["categories"])
##prints
[{'title': 'bla', 'categories': [{'title': 'bli', 'categories': [{'title': 'blu'}]}]}]
Strange... Can you confirm that the snippet works if you re-assign the schema directly after setting it None without "reconnecting" to GIS("home")?
from arcgis.gis import GIS
agol = GIS("home")
agol.users.categories = None
user_schema = {
'memberCategorySchema': [
{
'title': 'Categories',
'categories': [
{
'title': 'bla',
'categories': [
{
'title': 'bli',
'categories': [
{
'title': 'blu'
}
]
}
]
}
]
}
]
}
agol.users.categories = user_schema
## results in error?!
## however with "reconnecting before re-assigning" it works:
# agol = GIS("home")
# agol.users.categories = user_schema
why the "re-connection"?
What error are you getting? It it this...
ValueError: A list or tuple must be given to set the categories.
I get this error if the categories is already set to None. Worked around it with the below.
from arcgis.gis import GIS
agol = GIS("home")
## only update to None if it is not already None
if agol.users.categories != None:
agol.users.categories = None
user_schema = {
'memberCategorySchema': [
{
'title': 'Categories',
'categories': [
{
'title': 'bla',
'categories': [
{
'title': 'bli',
'categories': [
{
'title': 'blu'
}
]
}
]
}
]
}
]
}
agol.users.categories = user_schema
print(agol.users.categories)
As soon as the users.categories are None I can not reasign the schema anymore... unless I'm reconnecting to agol once more (agol = GIS("home")) before asigning the schema. Doing it in one run without reconnecting results in the error: ...in categories
for category in self._gis.users.categories[0]["categories"]:
IndexError: list index out of range
I'll try with the latest arcgis api version 2.2.x (rigthnow using 2.1.x) and also outside our internal-network. I'll provide an update later 🙂
Seems to work with 2.2.0.x 👍
Did not check if internal-network or 2.1.x was the issue tho.