-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcontrolprofilemanager.py
156 lines (142 loc) · 7.05 KB
/
controlprofilemanager.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
#This software is released under GNU public license. See details in the URL:
#http://www.gnu.org/copyleft/gpl.html
from controlbase import ControlBase
from AccessControl import ClassSecurityInfo
import Globals
from Acquisition import aq_base
import utility
import zExceptions
import com.db
class ControlProfileManager(ControlBase):
"Input text class"
meta_type = "ControlProfileManager"
security = ClassSecurityInfo()
control_title = 'Profile'
security.declareProtected('View management screens', 'edit')
def edit(self, *args, **kw):
"Inline edit short object"
temp = []
temp.append('<div class="">')
temp.append(self.saveCurrentProfileControl())
temp.append(self.quickProfForm())
temp.append('<div>')
if self.profile:
temp.append(self.clearProfile())
if self.masterLocation is None or self.masterLocation and self.masterLocation != self.getCompoundDoc().getPath():
temp.append('<p>')
temp.append(self.create_button('master', 'Master Profile Set'))
temp.append('</p>')
if self.masterLocation is not None:
temp.append('<p>')
temp.append(self.create_button('unsetMaster', 'Unset the master'))
temp.append('</p>')
temp.append('</div>')
temp.append('<p>Make this document into a profile: </p>')
temp.append('<p>This name can only have numbers and letters in it.</p>')
temp.append(self.input_text('profileName', ''))
temp.append(self.submitChanges())
temp.append('<p>Path: %s</p>' % self.input_text('path', ''))
temp.append('<p>Profile: %s</p>' % self.drawProfilesAvailable())
temp.append('<p>Profile to change to: %s</p>' % self.draw_profiles('profileTypeChange'))
temp.append(self.create_button('multiple_change', 'Multiple Change'))
temp.append(self.create_button('multiple_change', 'Multiple Change Rendering'))
cdoc = self.getCompoundDoc()
temp.append('<p>Select the types of objects that you want this profile to keep when it is changed.</p>')
temp.append('<p>There are %s currently selected items.</p>' % len(cdoc.getProfileTypeKeep()))
available =[''] + cdoc.availableObjects()
temp.append('<p>%s</p>' % cdoc.multiselect('profileTypeKeep', available, cdoc.getProfileTypeKeep(), size=10))
temp.append(self.submitChanges())
if self.REQUEST.other.get('results', ''):
temp += ["<p>%s</p>" % i for i in self.REQUEST.other['results']]
temp.append('</div>')
return ''.join(temp)
security.declarePrivate('saveCurrentProfileControl')
def saveCurrentProfileControl(self):
"Draw a control to save the current profile"
if self.profile and self.profile != 'None':
button = self.create_button('profileSave', self.profile)
return '<p>Save this Profile %s</p>' % button
return ''
security.declarePrivate('quickProfForm')
def quickProfForm(self):
"This is an inline quick selecter for layouts and profiles."
return self.profSelector()
security.declarePrivate('clearProfile')
def clearProfile(self):
"This is an inline quick selecter for layouts and profiles."
return self.create_button('profileUnset', 'Unset Profile')
security.declarePrivate('profSelector')
def profSelector(self):
"This is the simple layout and profile selector."
changeProfile = self.create_button("profile_action", "Change Profile")
changeRendering = self.create_button("profile_action", "Change Rendering Code")
return self.draw_profiles() + changeProfile + changeRendering
security.declarePrivate('before_manage_edit')
def before_manage_edit(self, form=None):
"This item is in charge of the profile/layout manager object"
cdoc = self.getCompoundDoc()
if 'master' in form:
self.resetMaster()
cdoc.setObject('masterLocation', cdoc.getPath())
if 'profileUnset' in form:
cdoc.profile = ''
self.resetMaster()
cdoc.delObjects(['masterLocation'])
if 'unsetMaster' in form:
self.resetMaster()
cdoc.delObjects(['masterLocation'])
if 'profile_action' in form:
if form['profile_action'] == "Change Profile":
self.changeProfile(form['profile'])
elif form['profile_action'] == "Change Rendering Code":
self.changeDisplay(form['profile'])
if 'profileName' in form and form['profileName']:
utility.objectStoreFile(aq_base(cdoc), form['profileName'])
if 'profileSave' in form and form['profileSave']:
utility.objectStoreFile(aq_base(cdoc), form['profileSave'])
if 'path' in form and form['path'] and 'multiple_change' in form:
renderOnly = 0
if form['multiple_change'] == 'Multiple Change Rendering':
renderOnly = 1
results = self.profileChanger(form['path'], form['profileTypeLimit'], form['profileTypeChange'], renderOnly)
self.REQUEST.other['results'] = results
security.declareProtected('CompoundDoc: Test', 'changeAllProfiles')
def changeAllProfiles(self):
"change to all profiles that this compounddoc has in sequence"
for i in utility.getStoredProfileNames():
self.changeProfile(i)
return 'KAPLAA!'
security.declarePrivate('profileChanger')
def profileChanger(self, path, profileLimit, profileSet, renderOnly = 0):
"change all the profiles from path on down"
catalog = self.getPhysicalRoot().CDocUpgrader
records = catalog(path=path, profile=profileLimit)
temp = []
self.REQUEST.other['okayToRunNotification'] = 0
#only load the pickle data once instead of every time
profile_data = utility.objectLoadFile(profileSet)
for record in com.db.subTrans(records, 100):
try:
cdoc = record.getObject()
if cdoc is not None:
if renderOnly:
cdoc.changeDisplay(doc=profile_data)
else:
cdoc.changeProfile(doc=profile_data)
temp.append(cdoc.absolute_url_path())
else:
utility.removeRecordFromCatalog(catalog, record)
except (zExceptions.Unauthorized, zExceptions.NotFound, KeyError):
pass
return temp
security.declarePrivate('draw_profiles')
def draw_profiles(self, varname='profile'):
"Draw the profiles"
temp = [''] + utility.getStoredProfileNames()
return self.option_select(temp, varname, [utility.renderNoneAsString(self.profile,'None')])
security.declarePrivate('drawProfilesAvailable')
def drawProfilesAvailable(self):
"Draw the profiles"
temp = [''] + list(self.getPhysicalRoot().CDocUpgrader.uniqueValuesFor('profile'))
return self.option_select(temp, 'profileTypeLimit', [getattr(self, 'profile', '')])
Globals.InitializeClass(ControlProfileManager)