Self hosted FLOSS fitness/workout, nutrition and weight tracker
Add new decorator to supress the post_save signal
Roland Geiderfc4040d8c647
diff --git a/wger/manager/models.py b/wger/manager/models.pyindex 6538f9a99..224cf668d 100644--- a/wger/manager/models.py+++ b/wger/manager/models.py@@ -31,6 +31,7 @@ from django.core.exceptions import ObjectDoesNotExistfrom wger.exercises.models import Exercisefrom wger.utils.helpers import DecimalJsonEncoder+from wger.utils.helpers import disable_for_loaddatalogger = logging.getLogger('workout_manager.custom')@@ -490,6 +491,7 @@ by the US Department of Agriculture. It is extremely complete, with around# Every new user gets a profile+@disable_for_loaddatadef create_user_profile(sender, instance, created, **kwargs):if created:UserProfile.objects.create(user=instance)diff --git a/wger/utils/helpers.py b/wger/utils/helpers.pyindex 0da02f3e4..4f7ad2471 100644--- a/wger/utils/helpers.py+++ b/wger/utils/helpers.py@@ -18,6 +18,9 @@ import loggingimport decimalimport json+from functools import wraps++logger = logging.getLogger('workout_manager.custom')@@ -34,3 +37,16 @@ class DecimalJsonEncoder(json.JSONEncoder):return str(obj)#return "%.2f" % objreturn json.JSONEncoder.default(self, obj)+++# Decorator to prevent clashes when loading data with loaddata and+# post_connect signals. See also:+# http://stackoverflow.com/questions/3499791/how-do-i-prevent-fixtures-from-conflicting+def disable_for_loaddata(signal_handler):+ @wraps(signal_handler)+ def wrapper(*args, **kwargs):+ if kwargs['raw']:+ #print "Skipping signal for %s %s" % (args, kwargs)+ return+ signal_handler(*args, **kwargs)+ return wrapper