18
18
19
19
CACHE_KEY = 'cached_auth_middleware:%s'
20
20
21
+ user_preprocessor = None
22
+ if hasattr (settings , 'CACHED_AUTH_PREPROCESSOR' ):
23
+ tmp = settings .CACHED_AUTH_PREPROCESSOR .split ("." )
24
+ module_name , function_name = "." .join (tmp [0 :- 1 ]), tmp [- 1 ]
25
+ func = getattr (__import__ (module_name , fromlist = ['' ]), function_name )
26
+ if callable (func ):
27
+ user_preprocessor = func
28
+ else :
29
+ raise Exception ("CACHED_AUTH_PREPROCESSOR_FUNCTION should be callable function with arguments user, request" )
30
+
21
31
try :
22
32
app_label , model_name = settings .AUTH_PROFILE_MODULE .split ('.' )
23
33
profile_model = models .get_model (app_label , model_name )
@@ -42,14 +52,8 @@ def get_cached_user(request):
42
52
user = AnonymousUser ()
43
53
if user is None :
44
54
user = get_user (request )
45
- if hasattr (settings , 'CACHED_AUTH_PREPROCESSOR_FUNCTION' ):
46
- tmp = settings .CACHED_AUTH_PREPROCESSOR_FUNCTION .split ("." )
47
- module_name , function_name = "." .join (tmp [0 :- 1 ]), tmp [- 1 ]
48
- func = getattr (__import__ (module_name , fromlist = ['' ]), function_name )
49
- if callable (func ):
50
- user = func (user , request )
51
- else :
52
- raise Exception ("CACHED_AUTH_PREPROCESSOR_FUNCTION should be callable function with arguments user, request" )
55
+ if user_preprocessor :
56
+ user_preprocessor (user , request )
53
57
# Try to populate profile cache if profile is installed
54
58
if profile_model :
55
59
try :
0 commit comments