-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
LabeledEnum helper property to replace Docflow #150
Comments
Wrapping the SQLAlchemy column will introduce non-trivial post-processing of the class, as required by annotations (#138). We could instead take the class JobPost(BaseMixin, db.Model):
_status = db.Column('status', db.Integer, default=POSTSTATUS.DRAFT, nullable=False)
status = LabeledEnumProperty(POSTSTATUS, _status) |
Hasjob shows another nuance. A status may be a combination of the status flag and something else: class JobPost(BaseMixin, db.Model):
…
def is_listed(self):
now = datetime.utcnow()
return (self.status in POSTSTATUS.LISTED) and (
self.datetime > now - agelimit) If we place such methods directly on the model, we'll have the API disparity of class JobPost(BaseMixin, db.Model):
_status = db.Column('status', db.Integer, default=POSTSTATUS.DRAFT, nullable=False)
status = LabeledEnumProperty(POSTSTATUS, _status)
status.add_state(
'CURRENTLY_LISTED',
POSTSTATUS.LISTED,
lambda post: post.datetime > datetime.utcnow() - agelimit
) Where |
It's not clear how such added states will be used for queries. This query: JobPost.query.filter(JobPost.status.CURRENTLY_LISTED) Expands to: JobPost.query.filter((JobPost.status == POSTSTATUS.CURRENTLY_LISTED, JobPost.datetime > datetime.utcnow() - agelimit)) …which is invalid syntax to JobPost.query.filter(*JobPost.status.CURRENTLY_LISTED) |
We don't yet know how to implement this |
Question: which of the following looks more correct?
|
|
The It should also support transitions conditional on more than one state manager. A model may have two state attributes, tracking the activity of independent actors (an author and a reviewer, for example). A transition on one of these state attributes should be available only if the other state attribute is in a specific state. For example, a proposal on Funnel may have two state attributes:
We currently can do this with the mechanism of added states that have a custom function evaluating the other state attribute. Chained transitions can also be achieved by using two decorators. However, this isn't good enough:
|
Conditional states (what added states are called as of 024cd1c) need a cache assertion indicating how long it is safe to assume the condition holds true or false. This is relevant when querying the state manager for available transitions, as it may not be optimal to test the conditions each time. The "available transitions" call will happen on UI renders. We also need reliable cache invalidation:
|
Transitions need to be undoable. This is not necessarily the same thing as having pairs of transitions going in both directions, but an explicit relationship between two transitions indicating one undoes the other. The original states must be preserved somewhere (where?) for the undo to happen. Signal handlers must also be notified of an undo. Since an undo will always happen in a different request, value management for affected fields (including the status field) is out of scope for the state manager. It will instead need a helper of some sort that can retrieve prior values. Push notifications will also need a recall action. Push notifications with no actual undo support (such as sending an email) may instead need to be buffered, which the undo operation should delete. |
|
|
This is the part I was hoping to build with ClassView. Since it manages the request and response, it can do state management. |
LabeledEnum
is now consistently used in HasGeek apps for status flag values. With the support for grouped values in #148, it now replaces the workflow state definition feature in Docflow.LabeledEnum version:
Docflow version:
LabeledEnum
's state values are lower level than the model that requires state values, whereasDocumentWorkflow
is a wrapper around the model and thus can't supply data essential to the model itself.However, Docflow provides two other features that
LabeledEnum
currently can't help with. Coaster should add support:State queries
Consider how status queries are done with
LabeledEnum
(from Hasjob'sJobPost
model):Contrast with Docflow:
LabeledEnum
requires a profusion of explicitly declared helper methods, whileDocumentWorkflow
constructs them automatically. However,DocumentWorkflow
requires the document to be wrapped in the workflow first, which imposes the additional requirement of having access to the wrapper (for example in a template, which has the object it receives and everything within it, but nothing external).It'll be nice if
LabeledEnum
came with a helper object that worked something like this:State transitions
The second feature that Docflow provides is state transitions, as in this example:
In this case the
LabeledEnumProperty
object can provide atransition
wrapper:The text was updated successfully, but these errors were encountered: