Skip to content

Commit

Permalink
make use of app config ready method on 1.7
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobh committed Aug 6, 2014
1 parent 10de187 commit 9550810
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
13 changes: 13 additions & 0 deletions django_fsm_log/apps.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,20 @@
from __future__ import unicode_literals
from django.apps import AppConfig
from django.conf import settings
from django.utils.module_loading import import_by_path

from django_fsm.signals import pre_transition, post_transition


class DjangoFSMLogAppConfig(AppConfig):
name = 'django_fsm_log'
verbose_name = "Django FSM Log"

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)
12 changes: 8 additions & 4 deletions django_fsm_log/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ def __unicode__(self):
self.transition
)

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)
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)

0 comments on commit 9550810

Please sign in to comment.