wuttafarm.web.util¶
Misc. utilities for web app
- wuttafarm.web.util.get_farmos_client_for_user(request, main_thread=True)[source]¶
Make and return a new farmOS API client instance.
This is a wrapper around
get_farmos_client()with conveniences to automatically handle token refresh for the current user session.- Parameters:
request – Current web request; this determines the user.
main_thread – Boolean indicating whether this client is for use within the main thread, or a separate one. In the latter case it must perform certain extra steps to help with token refresh. This defaults to
Truein which case the client is part of the main thread, i.e. the normal request/response cycle.
- Returns:
farmOS API client instance
- wuttafarm.web.util.save_farmos_oauth2_token(request, token, main_thread=True)[source]¶
Common logic for saving the given OAuth2 token within the user session. This function is called from 2 places:
wuttafarm.web.views.auth.farmos_oauth_callback()wuttafarm.web.views.farmos.master.FarmOSMasterView.get_farmos_client()