Created
October 15, 2012 20:39
-
-
Save frutik/3895289 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.db import models | |
from django.db import models | |
import xworkflows | |
from django_xworkflows import models as dxmodels | |
class TransitionLog(dxmodels.BaseTransitionLog): | |
# This is where we'll store the modified object | |
my = models.ForeignKey('My') | |
# Extra data to keep about transitions | |
ip = models.CharField(max_length=24, blank=True) | |
source = models.CharField(max_length=24, blank=True) | |
# Set the name of the field where the modified object goes | |
MODIFIED_OBJECT_FIELD = 'my' | |
# Define extra logging attributes | |
EXTRA_LOG_ATTRIBUTES = ( | |
('ip', 'ip', ''), # Transitions are called with 'ip' kwarg | |
('source', 'source', ''), # Transitions are called with 'ip' kwarg | |
) | |
class MyWorkflowImplWrapper(xworkflows.base.ImplementationWrapper): | |
def _post_transition(self, result, *args, **kwargs): | |
super(MyWorkflowImplWrapper, self)._post_transition(self, result, *args, **kwargs) | |
#print self, result, args, kwargs | |
#print type(self.instance), self.instance.id, self.field_name, self.transition.name, self.workflow | |
print self.instance.__module__, self.instance.__class__.__name__, 'entered state', self.transition.name | |
class MyWorkflow(dxmodels.Workflow): | |
log_model_class = TransitionLog | |
states = ( | |
('foo', u"Foo"), | |
('bar', u"Bar"), | |
('baz', u"Baz"), | |
) | |
transitions = ( | |
('foobar', 'foo', 'bar'), | |
('gobaz', ('foo', 'bar'), 'baz'), | |
('bazbar', 'baz', 'bar'), | |
) | |
initial_state = 'foo' | |
implementation_class = MyWorkflowImplWrapper | |
class My(dxmodels.WorkflowEnabled, models.Model): | |
state = dxmodels.StateField(MyWorkflow) | |
other = models.CharField(max_length=4) |
Author
frutik
commented
Oct 15, 2012
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment