diff options
| author | Alex Gaynor <alex.gaynor@gmail.com> | 2011-05-31 15:43:19 +0000 |
|---|---|---|
| committer | Alex Gaynor <alex.gaynor@gmail.com> | 2011-05-31 15:43:19 +0000 |
| commit | 1cfb00dc4164f7a5342c1866a50485b1c2845cb7 (patch) | |
| tree | cc850e12bdb36359a0d41c84bbb17f176c2848a9 /django/contrib/auth/context_processors.py | |
| parent | 45317677008a71c261b8c00388e8c2555a96598c (diff) | |
Cleaned up how ``request.user`` is set, this is a follow up to [16297]. Thanks for the review Luke.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@16305 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/contrib/auth/context_processors.py')
| -rw-r--r-- | django/contrib/auth/context_processors.py | 26 |
1 files changed, 7 insertions, 19 deletions
diff --git a/django/contrib/auth/context_processors.py b/django/contrib/auth/context_processors.py index ad72cd80fc..3ffab01e94 100644 --- a/django/contrib/auth/context_processors.py +++ b/django/contrib/auth/context_processors.py @@ -1,5 +1,3 @@ -from django.utils.functional import lazy, memoize, SimpleLazyObject - # PermWrapper and PermLookupDict proxy the permissions system into objects that # the template system can understand. @@ -36,23 +34,13 @@ def auth(request): If there is no 'user' attribute in the request, uses AnonymousUser (from django.contrib.auth). """ - # If we access request.user, request.session is accessed, which results in - # 'Vary: Cookie' being sent in every request that uses this context - # processor, which can easily be every request on a site if - # TEMPLATE_CONTEXT_PROCESSORS has this context processor added. This kills - # the ability to cache. So, we carefully ensure these attributes are lazy. - # We don't use django.utils.functional.lazy() for User, because that - # requires knowing the class of the object we want to proxy, which could - # break with custom auth backends. LazyObject is a less complete but more - # flexible solution that is a good enough wrapper for 'User'. - def get_user(): - if hasattr(request, 'user'): - return request.user - else: - from django.contrib.auth.models import AnonymousUser - return AnonymousUser() + if hasattr(request, 'user'): + user = request.user + else: + from django.contrib.auth.models import AnonymousUser + user = AnonymousUser() return { - 'user': SimpleLazyObject(get_user), - 'perms': lazy(lambda: PermWrapper(get_user()), PermWrapper)(), + 'user': user, + 'perms': PermWrapper(user), } |
