-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbasetab.py
More file actions
165 lines (141 loc) · 6.02 KB
/
basetab.py
File metadata and controls
165 lines (141 loc) · 6.02 KB
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
# -*- coding: utf-8 -*-
###########################################################################
# Copyright (C) 2003 by kosh
# <kosh@kosh.aesaeion.com>
#
# Copyright: See COPYING file that comes with this distribution
#
###########################################################################
from base import Base
#For Security control and init
from AccessControl import ClassSecurityInfo
import Globals
import nestedlisturl as NestedListURL
import utility
class BaseTab(Base):
"Basic item to make multi tabbed interfaces"
meta_type = "BaseTab"
security = ClassSecurityInfo()
overwrite=1
displayType = 'edit'
tabMapping = None
tabOrder = None
renderer = 'Horizontal'
columns = 0
configScript = ''
active = 1
classConfig = {}
classConfig['renderer'] = {'name':'Rendering Output', 'type':'list', 'values': NestedListURL.lookup.keys()}
classConfig['configScript'] = {'name':'Path to script configuration for tabs', 'type':'path'}
classConfig['active'] = {'name':'Activate the tab manager?', 'type': 'radio'}
configurable = ('configScript', 'active', 'renderer', 'tabOrder', 'tabMapping')
security.declarePrivate('getTabMapping')
def getTabMapping(self, name):
"get the tabMapping from this name"
if self.tabMapping is not None:
return self.tabMapping.get(name, name)
return name
security.declareProtected('View management screens', 'edit')
def edit(self, *args, **kw):
"Inline edit view"
temp = []
typeformat = '<div>Id: %s Display:%s</div>'
cdoc = self.getCompoundDoc()
displays = ['']
if cdoc.DisplayManager is not None:
displays.extend(cdoc.DisplayManager.displayUsage(self.displayType))
if cdoc.displayMap is not None:
displays.extend(cdoc.displayMap.keys())
tabOrder = self.tabOrder
if tabOrder is None:
tabOrder = []
neededEntries = len(tabOrder) + 1
temp.append(self.editSingleConfig('renderer'))
temp.append(NestedListURL.editRenderer(self.renderer, self))
tabMapping = self.tabMapping
if tabMapping is None:
tabMapping = {}
for index in xrange(neededEntries):
try:
nameValue = tabOrder[index]
displayValue = tabMapping[nameValue]
except (IndexError,KeyError):
nameValue = ''
displayValue = ''
temp.append(typeformat % (self.input_text('name', nameValue, containers=('tabMapping', str(index))),
self.option_select(displays, 'display', [displayValue], containers=('tabMapping', str(index)))))
return ''.join(temp)
security.declarePrivate('before_manage_edit')
def before_manage_edit(self, dict):
"Process edits."
tabMapping = dict.pop('tabMapping', None)
if tabMapping is not None:
temp = {}
for i, j in tabMapping.items():
temp[int(i)] = j
temp = ((dictionary['name'].strip(), dictionary['display'].strip()) for index, dictionary in sorted(temp.iteritems()))
cleaned = [(name, display) for name, display in temp if name and display]
if len(cleaned):
tabOrder = [name for name, value in cleaned]
self.setObject('tabOrder', tabOrder)
temp = {}
for name, display in cleaned:
temp[name] = display
self.setObject('tabMapping', temp)
else:
self.delObjects(('tabOrder', 'tabMapping'))
security.declarePrivate('getTabOrder')
def getTabOrder(self, doc=None, tabScript=None):
"get the tabOrder list structure"
doc = doc or self.getCompoundDoc()
query = utility.getQueryDict(self.REQUEST.environ.get('QUERY_STRING', ''))
configScript = tabScript or self.getConfigScript()
if configScript is not None:
return self.correctScriptTabOrder(configScript(doc), query)
tabOrder = self.getConfig('tabOrder')
if tabOrder is not None:
return [(name,name, '', {}, query) for name in tabOrder]
return []
security.declarePrivate('correctScriptTabOrder')
def correctScriptTabOrder(self, seq, query):
"correct the script tabOrder to account for the dictionary that can be used to pass in vars"
temp = []
for item in seq:
try:
url,link,cssClasses = item
queryDict = {}
except ValueError:
url,link,cssClasses,queryDict = item
temp.append([url,link,cssClasses,queryDict, query])
return temp
security.declarePrivate('getConfigScript')
def getConfigScript(self):
"return the config script object"
configScript = self.getConfig('configScript')
script = None
if configScript:
script = self.getCompoundDocContainer().restrictedTraverse(configScript, None)
return script
security.declarePrivate('getTabActive')
def getTabActive(self):
"return True only if we are set as active and we have data"
return self.getConfig('active') and (self.getConfig('tabMapping') is not None or self.getConfig('configScript'))
security.declarePrivate('beforeProfileLoad')
def beforeProfileLoad(self):
"run this action before loading the object with profile information"
self.performUpdate()
security.declarePrivate('classUpgrader')
def classUpgrader(self):
"upgrade this class"
self.fixTabOrder()
security.declarePrivate('fixTabOrder')
def fixTabOrder(self):
"fix the tabOrder object"
if not self.hasObject('tabOrder'):
if self.tabMapping is not None:
keys = sorted(self.tabMapping.keys())
else:
keys = None
self.setObject('tabOrder', keys)
fixTabOrder = utility.upgradeLimit(fixTabOrder, 141)
Globals.InitializeClass(BaseTab)