-
Notifications
You must be signed in to change notification settings - Fork 1
/
control_panel.py
227 lines (159 loc) · 6.21 KB
/
control_panel.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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
# -*- coding: UTF-8 -*-
# Copyright (C) 2010 Taverne Sylvain <[email protected]>
# Copyright (C) 2010-2011 Henry Obein <[email protected]>
# Copyright (C) 2011 Hervé Cauwelier <[email protected]>
# Copyright (C) 2011 Nicolas Deram <[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.core import thingy_property
from itools.datatypes import Boolean
from itools.gettext import MSG
from itools.uri import get_reference
from itools.web import BaseView, get_context
# Import from ikaaro
from ikaaro.cc import SubscribeForm
from ikaaro.control_panel import ControlPanelMenu, ControlPanel
from ikaaro.file_views import File_ExternalEdit_View
from ikaaro.folder_views import GoToSpecificDocument
from ikaaro.resource_views import DBResource_Links, DBResource_Backlinks
from ikaaro.revisions_views import DBResource_CommitLog
# Import from itws
from utils import is_navigation_mode
###################################################
# Control panel Views
###################################################
class ITWS_ControlPanelMenu(ControlPanelMenu):
title = MSG(u'Advanced')
def get_items(self):
items = super(ITWS_ControlPanelMenu, self).get_items()
# Hook icons
resource = self.resource
for item in items:
name = item['href'][1:] # remove ';'
view = resource.get_view(name)
if hasattr(view, 'itws_icon'):
icon = '/ui/itws-icons/16x16/%s/' % view.itws_icon
item['src'] = icon
return items
class ITWS_ControlPanel(ControlPanel):
title = MSG(u'Advanced')
context_menus = [ITWS_ControlPanelMenu()]
# Hide sidebar
display_sidebar = False
def get_namespace(self, resource, context):
# XXX We override get_namespace just to fix problem
# with icons uri
proxy = super(ITWS_ControlPanel, self)
namespace = proxy.get_namespace(resource, context)
items = namespace['items']
# Hook icons
for item in items:
name = item['url'][1:] # remove ';'
view = resource.get_view(name)
if hasattr(view, 'itws_icon'):
icon = '/ui/itws-icons/48x48/%s/' % view.itws_icon
item['icon'] = icon
namespace['batch'] = None
namespace['title'] = MSG(u'Control Panel')
return namespace
###############################################
# Control panel items
###############################################
# XXX ikaaro base control panel views do not display
# itws customized context_menus
context_menus = [ITWS_ControlPanelMenu()]
class CPEditTags(GoToSpecificDocument):
access = 'is_allowed_to_edit'
title = MSG(u'Tags')
description = MSG(u'Edit tags')
itws_icon = 'tags.png'
specific_document = 'tags'
specific_view = 'browse_content'
class CPEdit404(GoToSpecificDocument):
access = 'is_allowed_to_edit'
title = MSG(u'404')
itws_icon = '404.png'
description = MSG(u'Edit 404')
specific_document = 'theme/404'
specific_view = 'edit'
class CPEditRobotsTXT(GoToSpecificDocument):
access = 'is_allowed_to_edit'
title = MSG(u'Robots.txt')
itws_icon = 'robots.png'
description = MSG(u'Edit robots.txt')
specific_document = 'robots.txt'
specific_view = 'edit'
class CPManageHomePageMedia(GoToSpecificDocument):
access = 'is_allowed_to_edit'
title = MSG(u'Home page')
itws_icon = 'home.png'
description = MSG(u'Manage home page content')
specific_document = 'ws-data'
specific_view = 'browse_content'
class CPDBResource_CommitLog(DBResource_CommitLog):
description = MSG(u'See last modifications')
itws_icon = 'git.png'
context_menus = context_menus
class CPDBResource_Links(DBResource_Links):
description = MSG(u'List resources that link to this resource')
itws_icon = 'links.png'
context_menus = context_menus
class CPDBResource_Backlinks(DBResource_Backlinks):
description = MSG(u'List backlinks of this resource')
itws_icon = 'backlinks.png'
context_menus = context_menus
class CPOrderItems(GoToSpecificDocument):
access = 'is_allowed_to_edit'
itws_icon = 'toc.png'
title = MSG(u'Manage TOC')
description = MSG(u'Select and order items of the table of contents of '
u'this section.')
specific_document = 'order-section'
context_menus = context_menus
class CPSubscribe(SubscribeForm):
itws_icon = 'subscriptions.png'
description = MSG(u'Subscribe to resources modifications')
context_menus = context_menus
class CPExternalEdit(File_ExternalEdit_View):
itws_icon = 'editor.png'
description = MSG(u'Edit with an external editor')
context_menus = context_menus
class CPFOSwitchMode(BaseView):
access = 'is_allowed_to_edit'
title = MSG(u'Change mode edition/navigation')
itws_icon = 'switch.png'
query_schema = {'mode': Boolean(default=False)}
@thingy_property
def description(self):
context = get_context()
if is_navigation_mode(context):
return MSG(u'Change to edition mode')
return MSG(u'Change to navigation mode')
def GET(self, resource, context):
if context.get_cookie('itws_fo_edit', Boolean):
context.set_cookie('itws_fo_edit', '0')
else:
context.set_cookie('itws_fo_edit', '1')
referer = context.get_referrer()
if referer:
ref = get_reference(referer)
if ref.path == '/;fo_switch_mode':
# Do no loop
goto = '/'
else:
goto = referer
else:
goto = '/'
return get_reference(goto)