Example #1
0
    def ready(self):
        backend = import_by_path(settings.DJANGO_FSM_LOG_STORAGE_METHOD)
        StateLog = self.get_model('StateLog')

        backend.setup_model(StateLog)

        pre_transition.connect(backend.pre_transition_callback)
        post_transition.connect(backend.post_transition_callback)
 def setUp(self):
     self.model = BlogPost()
     self.pre_transition_called = False
     self.post_transition_called = False
     pre_transition.connect(self.on_pre_transition, sender=BlogPost)
     post_transition.connect(self.on_post_transition, sender=BlogPost)
Example #3
0
from django_fsm.signals import pre_transition, post_transition

from .managers import StateLogManager
from .utils import import_class_by_path


class StateLog(models.Model):
    timestamp = models.DateTimeField(default=now)
    by = models.ForeignKey(getattr(settings, 'AUTH_USER_MODEL', 'auth.User'), blank=True, null=True)
    state = models.CharField(max_length=255, db_index=True)
    transition = models.CharField(max_length=255)

    content_type = models.ForeignKey(ContentType)
    object_id = models.PositiveIntegerField(db_index=True)
    content_object = GenericForeignKey('content_type', 'object_id')

    objects = StateLogManager()

    def __unicode__(self):
        return '{} - {} - {}'.format(
            self.timestamp,
            self.content_object,
            self.transition
        )

backend = import_class_by_path(settings.DJANGO_FSM_LOG_STORAGE_METHOD)
backend.setup_model(StateLog)
pre_transition.connect(backend.pre_transition_callback)
post_transition.connect(backend.post_transition_callback)
Example #4
0
 def setUp(self):
     self.model = BlogPost()
     self.pre_transition_called = False
     self.post_transition_called = False
     pre_transition.connect(self.on_pre_transition, sender=BlogPost)
     post_transition.connect(self.on_post_transition, sender=BlogPost)
Example #5
0
    object_id = models.PositiveIntegerField(db_index=True)
    content_object = GenericForeignKey('content_type', 'object_id')

    objects = StateLogManager()
    
    class Meta:
        get_latest_by = 'timestamp'

    def __str__(self):
        return '{} - {} - {}'.format(
            self.timestamp,
            self.content_object,
            self.transition
        )

    def get_state_display(self):
        fsm_obj = self.content_object
        for field in fsm_obj._meta.fields:
            if isinstance(field, FSMFieldMixin):
                state_display = dict(field.flatchoices).get(self.state, self.state)
                return force_text(state_display, strings_only=True)

try:
    import django.apps
except: # django < 1.7
    backend = import_by_path(settings.DJANGO_FSM_LOG_STORAGE_METHOD)
    backend.setup_model(StateLog)

    pre_transition.connect(backend.pre_transition_callback)
    post_transition.connect(backend.post_transition_callback)
Example #6
0
 def setUp(self):
     self.pre_transition_called = False
     self.post_transition_called = False
     pre_transition.connect(self.on_pre_transition, sender=MultiResultTest)
     post_transition.connect(self.on_post_transition, sender=MultiResultTest)