-
Notifications
You must be signed in to change notification settings - Fork 0
/
context_processors.py
62 lines (46 loc) · 1.38 KB
/
context_processors.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import logging
from django.conf import settings as the_settings
from django import contrib
from django.contrib.sites.requests import RequestSite
from marto_python.util import is_site_view
from marto_python.url import get_server_url
logger = logging.getLogger(__name__)
def site_view_only(func):
def inner(request):
return func(request) if is_site_view(request.path) else {}
return inner
@site_view_only
def messages(request):
if 'messages' in request.session:
msgs = request.session['messages']
request.session['messages'] = None
return {'messages': msgs}
else:
return {}
def get_contrib_messages_data(request):
msgs = contrib.messages.get_messages(request)
rv = []
for msg in msgs:
rv.append({
'message': msg.message,
'level': msg.level,
'level_tag': msg.level_tag,
'tags': msg.tags,
'extra_tags': msg.extra_tags,
})
return rv
@site_view_only
def contrib_messages_data(request):
return {'messages_data': get_contrib_messages_data(request)}
@site_view_only
def settings(request):
return {'settings': the_settings}
@site_view_only
def site(request):
return {
'site': RequestSite(request),
'server_url': get_server_url(),
}
@site_view_only
def current_path(request):
return {'current_path': request.get_full_path()}