File tree Expand file tree Collapse file tree 1 file changed +9
-10
lines changed Expand file tree Collapse file tree 1 file changed +9
-10
lines changed Original file line number Diff line number Diff line change 15
15
except ImportError :
16
16
from django .contrib .auth .models import User
17
17
18
-
19
18
CACHE_KEY = 'cached_auth_middleware:%s'
20
19
20
+
21
+ def profile_preprocessor (user , request ):
22
+ """ Cache user profile """
23
+ return user .get_profile ()
24
+
21
25
user_preprocessor = None
22
26
if hasattr (settings , 'CACHED_AUTH_PREPROCESSOR' ):
23
27
tmp = settings .CACHED_AUTH_PREPROCESSOR .split ("." )
26
30
if callable (func ):
27
31
user_preprocessor = func
28
32
else :
29
- raise Exception ("CACHED_AUTH_PREPROCESSOR_FUNCTION should be callable function with arguments user, request" )
33
+ raise Exception ("CACHED_AUTH_PREPROCESSOR must be callable with 2 arguments user and request" )
34
+ else :
35
+ user_preprocessor = profile_preprocessor
30
36
31
37
try :
32
38
app_label , model_name = settings .AUTH_PROFILE_MODULE .split ('.' )
@@ -53,14 +59,7 @@ def get_cached_user(request):
53
59
if user is None :
54
60
user = get_user (request )
55
61
if user_preprocessor :
56
- user_preprocessor (user , request )
57
- # Try to populate profile cache if profile is installed
58
- if profile_model :
59
- try :
60
- user .get_profile ()
61
- # Handle exception for user with no profile and AnonymousUser
62
- except (profile_model .DoesNotExist , AttributeError ):
63
- pass
62
+ user = user_preprocessor (user , request )
64
63
cache .set (key , user )
65
64
request ._cached_user = user
66
65
return request ._cached_user
You can’t perform that action at this time.
0 commit comments