Self hosted FLOSS fitness/workout, nutrition and weight tracker
Make the key mapper more robust
Roland Geiderba0aa9f7b393
diff --git a/wger/utils/cache.py b/wger/utils/cache.pyindex c80f1a0a0..95abecec9 100644--- a/wger/utils/cache.py+++ b/wger/utils/cache.py@@ -56,10 +56,10 @@ class CacheKeyMapper(object):'''Return the exercise cache key'''- if type(param) == int:- pk = param- else:+ try:pk = param.pk+ except AttributeError:+ pk = paramreturn self.EXERCISE_CACHE_KEY.format(pk)@@ -67,10 +67,10 @@ class CacheKeyMapper(object):'''Return the exercise muscle background cache key'''- if type(param) == int:- pk = param- else:+ try:pk = param.pk+ except AttributeError:+ pk = paramreturn self.EXERCISE_CACHE_KEY_MUSCLE_BG.format(pk)@@ -78,10 +78,10 @@ class CacheKeyMapper(object):'''Return the language cache key'''- if type(param) in (str, unicode):+ try:+ pk = param.pk+ except AttributeError:pk = param- else:- pk = param.short_namereturn self.LANGUAGE_CACHE_KEY.format(pk)@@ -89,10 +89,10 @@ class CacheKeyMapper(object):'''Return the language cache key'''- if type(param) in (str, unicode):+ try:+ pk = param.pk+ except AttributeError:pk = param- else:- pk = param.short_namereturn self.LANGUAGE_CONFIG_CACHE_KEY.format(pk, item)@@ -100,10 +100,10 @@ class CacheKeyMapper(object):'''Return the ingredient cache key'''- if type(param) == int:- pk = param- else:+ try:pk = param.pk+ except AttributeError:+ pk = paramreturn self.INGREDIENT_CACHE_KEY.format(pk)@@ -111,10 +111,10 @@ class CacheKeyMapper(object):'''Return the workout muscle background cache key'''- if type(param) == int:- pk = param- else:+ try:pk = param.pk+ except AttributeError:+ pk = paramreturn self.WORKOUT_MUSCLE_BG.format(pk)