-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathskin_views.py
189 lines (158 loc) · 6.49 KB
/
skin_views.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
# -*- coding: UTF-8 -*-
# Copyright (C) 2010-2011 Henry Obein <[email protected]>
# Copyright (C) 2010-2011 Taverne Sylvain <[email protected]>
# Copyright (C) 2011 Hervé Cauwelier <[email protected]>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# Import from itools
from itools.gettext import MSG
from itools.stl import STLTemplate
from itools.uri import decode_query
# Import from ikaaro
from ikaaro.folder import Folder
from ikaaro.workflow import WorkflowAware
# Import form itws
from itws.utils import is_navigation_mode
# Import from shop
from utils import get_shop
class AdminBarTemplate(STLTemplate):
show_edition_tabs = True
def __init__(self, context):
self.context = context
def get_template(self):
resource = self.context.resource
return resource.get_resource('/ui/backoffice/admin_bar.xml')
def workflow(self):
resource = self.context.resource
if isinstance(resource, WorkflowAware):
return 'wf-%s' % resource.get_property('state')
return None
def resource_type(self):
resource = self.context.resource
return resource.class_title
def tabs(self):
context = self.context
user = context.user
if user is None:
return []
# Do not show tabs on some site root views
nav = (context.site_root.class_control_panel +
['control_panel', 'contact',
'site_search', 'website_new_resource'])
if (context.site_root == context.resource and
context.view_name in nav):
return []
# Build tabs (Same that upper class)
# Get resource & access control
context = self.context
here = context.resource
here_link = context.get_link(here)
is_folder = isinstance(here, Folder)
# Tabs
tabs = []
for link, view in here.get_views():
active = False
# From method?param1=value1¶m2=value2&...
# we separate method and arguments, then we get a dict with
# the arguments and the subview active state
if '?' in link:
name, args = link.split('?')
args = decode_query(args)
else:
name, args = link, {}
# Active
if context.view == here.get_view(name, args):
active = True
# Ignore new_resource
if link == 'new_resource':
continue
# Add the menu
tabs.append({
'name': '%s/;%s' % (here_link, link),
'icon': getattr(view, 'adminbar_icon', None),
'rel': getattr(view, 'adminbar_rel', None),
'label': view.get_title(context),
'active': active,
'class': active and 'active' or None})
# New resources
if is_folder:
document_types = here.get_document_types()
if len(document_types) > 0:
active = context.view_name == 'new_resource'
href = './;new_resource'
label = MSG(u'Add content')
if len(document_types) == 1:
href += '?type='+ document_types[0].class_id
class_title = document_types[0].class_title
label = MSG(u"Add '{x}'").gettext(x=class_title)
tabs.append({'name': href,
'label': label,
'icon': 'page-white-add',
'rel': None,
'class': active and 'active' or None})
return tabs
def edition_tabs(self):
views = []
if self.show_edition_tabs is False:
return []
context = self.context
navigation_mode = is_navigation_mode(context)
# edit mode
views.append({'name': '/;fo_switch_mode?mode=1',
'label': MSG(u'On'),
'class': 'active' if not navigation_mode else None})
views.append({'name': '/;fo_switch_mode?mode=0',
'label': MSG(u'Off'),
'class': 'active' if navigation_mode else None})
return views
def backoffice_tabs(self):
context = self.context
site_root = context.site_root
user = context.user
shop = get_shop(site_root)
tabs = []
is_site_root = site_root == context.resource
# Go home
active = is_site_root and context.view_name in (None, 'view')
tabs.append({'name': '/',
'label': MSG(u'Go home'),
'icon': 'house-go',
'class': active and 'active' or None})
# Open backoffice
tabs.append({'name': shop.get_property('shop_backoffice_uri'),
'label': MSG(u'Backoffice'),
'icon': 'cog',
'class': None})
# Site root access control
ac = site_root.get_access_control()
# New resource
active = is_site_root and context.view_name == 'website_new_resource'
view = site_root.get_view('website_new_resource')
if view and ac.is_access_allowed(user, site_root, view):
tabs.append({'name': '/;website_new_resource',
'label': MSG(u'Create a new resource'),
'icon': 'page-white-add',
'class': active and 'active' or None})
# Logout
tabs.append({'name': '/;logout',
'label': MSG(u'Log out'),
'icon': 'action-logout',
'class': active and 'active' or None})
return tabs
def get_namespace(self):
return {'backoffice_tabs': self.backoffice_tabs(),
'tabs': self.tabs(),
'resource_type': self.resource_type(),
'edition_tabs': self.edition_tabs(),
'workflow': self.workflow}