cubicweb #1409785 API to set and test "flag" on entity [open]
There is several case where it's useful to mark that an involved entity is temporary in a specific state. This marker can affect selection of hooks or change the behaviour of piece of code.
We are using the concept extensively in a project to we enforce the size of image and generate thumbnail of different size.
Such flag are usually achieve by putting the entity eid into a set stored in the transaction_data when the entity enter this state and removing it when the entity leave this state.
However, write access to transaction_data are not available at the webserver side. Making a generic write access to transaction_data available at the web-server side is hard and error prone because of the pyro proxy.
Getting a specific API to read and write flag data is much more easy. By hiding access to transaction_data and reentrant logic, A specific API clarify the all part of the code.
the "flag" API will have 3 components
The cw_flag and cw_flagged method could be available thought a selector.
The cw_flag and cw_flagged methods are added to AnyEntity (or an adapter)
An EntityFlag class will handle the context management part, with necessary reentrant capability.
The Request -> Connection -> Repository chain needs to implement three methods flag_entity, unflag_entity, flagged_entity to read and write flag information. Those methods shall not be used directly. They will be call through the cw_flag and cw_flagged of AnyEntity.
Flag key will get necessary prefix not to conflict with other content of transaction_data.
See attached python files for current implementation in our project.
|done in||<not specified>|
|closed by||<not specified>|