What I’m trying to do:
I have created a layout with 6 pages that use the layout. At startup I show the main page (NOT based on the layout) and if a user selects a project the first page using the layout is shown. I pass the project_id into the properties parameters. On that page the project is loaded from the database. I now want to share that object on any page that is based on the layout.
What I’ve tried and what’s not working:
I have tried to add a field to the layout but that does not work since every form based on the layout has a different instance of the layout object.
My current solution is to store the id of the project being edited in a database and use a database query on every page to find the currently selected object but this adds overhead which I hope to reduce.
Code Sample:
# this is the code I use now (on every page that uses the layout)
# is the page called from the main page then the project_id is given in the properties dict
if 'project_id' in properties.keys():
project_id= properties['project_id']
anvil.server.call('set_active_project_id', anvil.users.get_user()['email'], project_id)
else:
project_id= anvil.server.call('get_active_project_id', anvil.users.get_user()['email'])