Module reahl.webdeclarative.webdeclarative¶
Am implementation of Reahl using SqlAlchemy Declarative.
Run ‘reahl componentinfo reahl-web-declarative’ for configuration information.
UserSession¶
- class reahl.webdeclarative.webdeclarative.UserSession(**kwargs)¶
Bases:
Base
,UserSessionProtocol
An implementation of
reahl.web.interfaces.UserSessionProtocol
of the Reahl framework.- classmethod for_current_session()¶
Returns a UserSession instance for the current user. If no UserSession is present for the current interaction yet this method should create one. If a UserSession does exist for the current interaction, this method returns the correct UserSession.
- classmethod initialise_web_session_on(context)¶
Fetch/create a new UserSession or do any initialisation or reinitialisation needed on it and set it on the given context as its .session attribute.
Called at the beginning of a request or after an abort during the request (which may require reinitialisation of the session so it may still be used after the abort).
- classmethod preserve_session(session)¶
Ensure the given session object is kept intact so that it can survive a transaction abort.
Added in version 5.2.
- classmethod restore_session(session)¶
After a transaction is aborted, this ensures the given session is restored to its state before the abort.
Added in version 5.2.
- get_csrf_token()¶
Fetch/create a suitable token for protecting against CSRF.
Added in version 5.2.
- is_secured()¶
Answers whether the interaction is currently done via a secure channel where applicable.
Added in version 3.1.
- is_active()¶
Answers whether the session is still usable (instead of being expired due to inactivity).
- set_last_activity_time()¶
Sets a timestamp on the UserSession to indicate when the last activity was detected relating to this interaction. UserSessions typically expire automatically if no activity is detected after some time.
- classmethod get_or_create_session()¶
Returns a session, creating a new one if none can be determined. If one can be determined from the browser, that session is returned.
- set_session_key(response)¶
Called at the end of a request loop to enable an implementation to save some identifying information to the response (such as setting a cookie with the ID of the current session).
- get_interface_locale()¶
Answers a string identifying the currently selected locale.
UserInput¶
- class reahl.webdeclarative.webdeclarative.UserInput(**kwargs)¶
Bases:
SessionData
,UserInputProtocol
An implementation of
reahl.web.interfaces.UserInputProtocol
. It represents a value that was input by a user.- classmethod get_previously_entered_for_form(form, input_name, entered_input_type)¶
Returns the user input associated with the given
reahl.web.ui.Form
, as previously saved using input_name as name.Changed in version 4.0: Added entered_input_type
- classmethod save_input_value_for_form(form, input_name, value, entered_input_type)¶
Persists value as the value of the user input associated with the given
reahl.web.ui.Form
, using input_name as name.Changed in version 4.0: Added entered_input_type
- classmethod get_persisted_for_view(view, key, value_type)¶
Returns the value associated with the given
reahl.web.fw.UrlBoundView
, as previously saved using key.Added in version 5.0.
- classmethod add_persisted_for_view(view, key, value, value_type)¶
Persists value associated with the given
reahl.web.fw.UrlBoundView
, to be retrieved using key.Added in version 5.0.
- classmethod remove_persisted_for_view(view, key)¶
Removes previously persisted value with the given
reahl.web.fw.UrlBoundView
, as previously saved using keyAdded in version 5.0.
PersistedException¶
- class reahl.webdeclarative.webdeclarative.PersistedException(**kwargs)¶
Bases:
SessionData
,PersistedExceptionProtocol
An implementation of
reahl.web.interfaces.PersistedExceptionProtocol
. It represents an Exception that was raised upon a user interaction.- classmethod save_exception_for_form(form, **kwargs)¶
Saves a an exception for the given
reahl.web.ui.Form
.Added in version 5.0.
- classmethod clear_for_form_except_inputs(form)¶
Clears the exception associated with this form, while leaving exeptions for invididual inputs intact.
Added in version 5.0.
- classmethod clear_for_all_inputs(form)¶
Removes all saved Exceptions associated with the given
reahl.web.ui.Form
.
- classmethod get_exception_for_form(form)¶
Retrieves an exception previously saved for the given
reahl.web.ui.Form
, or None if not found.
- classmethod get_exception_for_input(form, input_name)¶
Retrieves an exception previously saved for the given
reahl.web.ui.Form
and input_name or None if not found.
PersistedFile¶
- class reahl.webdeclarative.webdeclarative.PersistedFile(**kwargs)¶
Bases:
SessionData
,PersistedFileProtocol
An implementation of
reahl.web.interfaces.PersistedFileProtocol
. It represents a file that was input by a user.- property file_obj¶
Returns an object with traditional .read and .seek methods which can be used to read the contents of the persisted file.
- classmethod get_persisted_for_form(form, input_name)¶
Returns the previously persisted file for the given
reahl.web.ui.Form
, using the given input_name as name.
- classmethod add_persisted_for_form(form, input_name, uploaded_file)¶
Saves the given uploaded_file (a
reahl.component.modelinterface.UploadedFile
) using the given input_name for the givenreahl.web.ui.Form
.
- classmethod remove_persisted_for_form(form, input_name, filename)¶
Removes previously persisted file with name filename, as saved for the given
reahl.web.ui.Form
and input_name.
- classmethod is_uploaded_for_form(form, input_name, filename)¶
Answers whether a file with name filename has previously been saved for the given
reahl.web.ui.Form
and input_name.