-
Notifications
You must be signed in to change notification settings - Fork 0
Roles
Developer From Jokela edited this page Nov 20, 2020
·
1 revision
To handle roles, you should check after login, if login result boolean roleSelectionRequired
is true
.
In that case, you should access login result's homepage
dict, and get roles homepage['roles']
.
Role structure:
{
'slug': '/!024291',
'name': 'Titta Tapola',
'type': 'student',
'primusId': 4291,
'formKey': 'student:4291:4b486e247da505a51abae3f9a0e524e8',
'photo': <PIL.JpegImagePlugin.JpegImageFile image mode=RGB size=130x139 at 0x7F1533572390>,
'earlyEduUser': False,
'school': 'Esimerkkilän peruskoulu (0-9)'
}
To activate role in SDK, you should make a call to setRole
, with your desired role dict as its parameter.
Example:
from wilmasdk.sdk import WilmaSDK
.....
if result.roleSelectionRequired:
# This selects the first role (do not use this code for production! just for example purposes)
role = result.homepage['roles'][0]
sdk.setRole(role)
homepageResult = sdk.getHomepage()
homepage = homepageResult.homepage
print("Successfully switched to " + homepage['name'] + " role")
After the role is set, you can continue making calls to SDK without any additions.