|
@@ -1,5 +1,8 @@
|
|
1
|
+from django.conf import settings
|
1
|
2
|
from django.utils.translation import gettext as _
|
2
|
3
|
from .help import actionbar as actionbar_add_help
|
|
4
|
+import inspect
|
|
5
|
+import logging
|
3
|
6
|
import os
|
4
|
7
|
from themes import gray_icon_url, color_icon_url
|
5
|
8
|
from users.context import menubar as menubar_user
|
|
@@ -7,6 +10,9 @@ from users.context import PROFILE_ENTRY_UID
|
7
|
10
|
import pygal
|
8
|
11
|
from pygal.models import get_item_by_rel_path
|
9
|
12
|
|
|
13
|
+logger = logging.getLogger(settings.ROOT_LOGGER_NAME).getChild(__name__)
|
|
14
|
+
|
|
15
|
+
|
10
|
16
|
MY_FAVOURITES_ENTRY_UID = 'my_favourites-main'
|
11
|
17
|
HELP_UID = 'help-main'
|
12
|
18
|
NAVIGATION_ENTRY_UID = 'navigation-main-%s'
|
|
@@ -15,60 +21,76 @@ SEARCH_ENTRY_UID = 'search-main'
|
15
|
21
|
BACK_ENTRY_UID = 'back-main'
|
16
|
22
|
|
17
|
23
|
|
18
|
|
-def context_adaption(context, request, rel_path, wrapper_instance=None, title='', current_help_page=None):
|
19
|
|
- context[context.MENUBAR].append_entry(HELP_UID, _('Help'), color_icon_url(request, 'help.png'), pygal.url_helpview(request, 'main'), True, False)
|
20
|
|
- menubar_user(context[context.MENUBAR], request)
|
21
|
|
- menubar(context[context.MENUBAR], request, rel_path)
|
22
|
|
- navigationbar(context[context.NAVIGATIONBAR], request, rel_path)
|
|
24
|
+def context_adaption(context, request, **kwargs):
|
|
25
|
+ caller_name = inspect.currentframe().f_back.f_code.co_name
|
|
26
|
+ wrapper_instance = kwargs.get("wrapper_instance")
|
|
27
|
+ #
|
|
28
|
+ menubar(context, request, **kwargs)
|
|
29
|
+ navigationbar(context, request, **kwargs)
|
23
|
30
|
if wrapper_instance is None:
|
24
|
31
|
# Pages without direct connection to an item (e.g. Helpview, ...)
|
25
|
|
- context.set_additional_title(title)
|
26
|
|
- context[context.ACTIONBAR].append_entry(
|
27
|
|
- BACK_ENTRY_UID, # uid
|
28
|
|
- _('Back'), # name
|
29
|
|
- color_icon_url(request, 'back.png'), # icon
|
30
|
|
- 'javascript:history.back()', # url
|
31
|
|
- True, # left
|
32
|
|
- False # active
|
33
|
|
- )
|
|
32
|
+ context.set_additional_title(kwargs.get("title", ""))
|
|
33
|
+ #
|
|
34
|
+ actionbar(context, request, caller_name)
|
34
|
35
|
else:
|
35
|
36
|
wrapper_instance.context_adaption(context)
|
36
|
37
|
# HELP
|
37
|
38
|
if pygal.is_helpview(request):
|
38
|
|
- actionbar_add_help(context, request, current_help_page=current_help_page)
|
39
|
|
-
|
40
|
|
-
|
41
|
|
-def menubar(bar, request, rel_path):
|
42
|
|
- if request.user.is_authenticated:
|
43
|
|
- bar.append_entry(*my_favourites_entry_parameters(request, rel_path))
|
44
|
|
- try:
|
45
|
|
- bar.replace_entry(PROFILE_ENTRY_UID, *profile_entry_parameters(request))
|
46
|
|
- except ValueError:
|
47
|
|
- pass # Profile entry does not exist, so exchange is not needed (e.g. no user is logged in)
|
48
|
|
-
|
49
|
|
-
|
50
|
|
-def navigationbar(bar, request, path):
|
|
39
|
+ actionbar_add_help(context, request, current_help_page=kwargs.get("current_help_page"))
|
|
40
|
+ for key in kwargs:
|
|
41
|
+ context[key] = kwargs[key]
|
|
42
|
+ logger.debug("context adapted: %s", repr(context))
|
|
43
|
+
|
|
44
|
+def navigationbar(context, request, **kwargs):
|
|
45
|
+ bar = context[context.NAVIGATIONBAR]
|
|
46
|
+ rel_path = kwargs.get("rel_path", '')
|
|
47
|
+ #
|
51
|
48
|
if pygal.is_favouriteview(request):
|
52
|
|
- if path:
|
53
|
|
- bar.append_entry(*navigation_entry_parameters(request, path, None))
|
54
|
|
- anchor = get_item_by_rel_path(path).name
|
|
49
|
+ if rel_path:
|
|
50
|
+ bar.append_entry(*navigation_entry_parameters(request, rel_path, None))
|
|
51
|
+ anchor = get_item_by_rel_path(rel_path).name
|
55
|
52
|
else:
|
56
|
53
|
anchor = None
|
57
|
54
|
elif pygal.is_searchview(request):
|
58
|
|
- if path:
|
59
|
|
- bar.append_entry(*navigation_entry_parameters(request, path, None))
|
60
|
|
- anchor = get_item_by_rel_path(path).name
|
|
55
|
+ if rel_path:
|
|
56
|
+ bar.append_entry(*navigation_entry_parameters(request, rel_path, None))
|
|
57
|
+ anchor = get_item_by_rel_path(rel_path).name
|
61
|
58
|
else:
|
62
|
59
|
anchor = None
|
63
|
60
|
else:
|
64
|
61
|
anchor = None
|
65
|
|
- while len(path) > 0 and path != os.path.sep:
|
66
|
|
- bar.append_entry(*navigation_entry_parameters(request, path, anchor))
|
67
|
|
- anchor = get_item_by_rel_path(path).name
|
68
|
|
- path = os.path.dirname(path)
|
|
62
|
+ while len(rel_path) > 0 and rel_path != os.path.sep:
|
|
63
|
+ bar.append_entry(*navigation_entry_parameters(request, rel_path, anchor))
|
|
64
|
+ anchor = get_item_by_rel_path(rel_path).name
|
|
65
|
+ rel_path = os.path.dirname(rel_path)
|
69
|
66
|
bar.append_entry(*home_entry_parameters(request, anchor))
|
70
|
67
|
|
71
|
68
|
|
|
69
|
+def menubar(context, request, **kwargs):
|
|
70
|
+ bar = context[context.MENUBAR]
|
|
71
|
+ rel_path = kwargs.get("rel_path", '')
|
|
72
|
+ #
|
|
73
|
+ bar.append_entry(HELP_UID, _('Help'), color_icon_url(request, 'help.png'), pygal.url_helpview(request, 'main'), True, False)
|
|
74
|
+ menubar_user(bar, request)
|
|
75
|
+ if request.user.is_authenticated:
|
|
76
|
+ bar.append_entry(*my_favourites_entry_parameters(request, rel_path))
|
|
77
|
+ try:
|
|
78
|
+ bar.replace_entry(PROFILE_ENTRY_UID, *profile_entry_parameters(request))
|
|
79
|
+ except ValueError:
|
|
80
|
+ pass # Profile entry does not exist, so exchange is not needed (e.g. no user is logged in)
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+def actionbar(context, request, caller_name, **kwargs):
|
|
84
|
+ bar = context[context.ACTIONBAR]
|
|
85
|
+ bar.append_entry(
|
|
86
|
+ BACK_ENTRY_UID, # uid
|
|
87
|
+ _('Back'), # name
|
|
88
|
+ color_icon_url(request, 'back.png'), # icon
|
|
89
|
+ 'javascript:history.back()', # url
|
|
90
|
+ True, # left
|
|
91
|
+ False # active
|
|
92
|
+ )
|
|
93
|
+
|
72
|
94
|
def profile_entry_parameters(request):
|
73
|
95
|
return (
|
74
|
96
|
PROFILE_ENTRY_UID, # uid
|