10
10
from django.conf import settings
11
from django.middleware.csrf import get_token
12
from django.utils.functional import lazy
14
Returns context variables required by apps that use Django's authentication
17
If there is no 'user' attribute in the request, uses AnonymousUser (from
20
if hasattr(request, 'user'):
23
from django.contrib.auth.models import AnonymousUser
24
user = AnonymousUser()
27
'messages': user.get_and_delete_messages(),
28
'perms': PermWrapper(user),
16
DEPRECATED. This context processor is the old location, and has been moved
17
to `django.contrib.auth.context_processors`.
19
This function still exists for backwards-compatibility; it will be removed
24
"The context processor at `django.core.context_processors.auth` is " \
25
"deprecated; use the path `django.contrib.auth.context_processors.auth` " \
27
PendingDeprecationWarning
29
from django.contrib.auth.context_processors import auth as auth_context_processor
30
return auth_context_processor(request)
34
Context processor that provides a CSRF token, or the string 'NOTPROVIDED' if
35
it has not been provided by either a view decorator or the middleware
38
token = get_token(request)
40
# In order to be able to provide debugging info in the
41
# case of misconfiguration, we use a sentinel value
42
# instead of returning an empty dict.
46
_get_val = lazy(_get_val, str)
48
return {'csrf_token': _get_val() }
31
50
def debug(request):
32
51
"Returns context variables helpful for debugging."
80
99
def __getitem__(self, module_name):
81
100
return PermLookupDict(self.user, module_name)
83
102
def __iter__(self):
84
103
# I am large, I contain multitudes.
85
104
raise TypeError("PermWrapper is not iterable.")