1 | #-*- mode: python; mode: fold -*- |
---|
2 | # (C) Copyright 2005 The WAeUP group <http://www.waeup.org> |
---|
3 | # Author: Joachim Schmitz (js@aixtraware.de) |
---|
4 | # |
---|
5 | # This program is free software; you can redistribute it and/or modify |
---|
6 | # it under the terms of the GNU General Public License version 2 as published |
---|
7 | # by the Free Software Foundation. |
---|
8 | # |
---|
9 | # This program is distributed in the hope that it will be useful, |
---|
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
12 | # GNU General Public License for more details. |
---|
13 | # |
---|
14 | # You should have received a copy of the GNU General Public License |
---|
15 | # along with this program; if not, write to the Free Software |
---|
16 | # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA |
---|
17 | # 02111-1307, USA. |
---|
18 | # |
---|
19 | # $Id: WAeUPTool.py 197 2006-02-08 12:47:31Z joachim $ |
---|
20 | """The WAeUPTool. |
---|
21 | """ |
---|
22 | |
---|
23 | from zLOG import LOG, DEBUG |
---|
24 | from Globals import InitializeClass, HTMLFile |
---|
25 | from AccessControl import ClassSecurityInfo |
---|
26 | from OFS.Folder import Folder |
---|
27 | |
---|
28 | from Products.CPSInstaller.CPSInstaller import CPSInstaller |
---|
29 | from Products.CMFCore.PortalFolder import PortalFolder |
---|
30 | from Products.CMFCore.permissions import View, ManagePortal |
---|
31 | from Products.CMFCore.utils import UniqueObject |
---|
32 | |
---|
33 | class WAeUPTool(UniqueObject,PortalFolder): |
---|
34 | """WAeUP tool""" |
---|
35 | |
---|
36 | id = 'portal_WAeUP' |
---|
37 | meta_type = 'WAeUP Tool' |
---|
38 | |
---|
39 | security = ClassSecurityInfo() |
---|
40 | manage_options = (#ActionProviderBase.manage_options + |
---|
41 | PortalFolder.manage_options[:1] + |
---|
42 | PortalFolder.manage_options[2:]) |
---|
43 | |
---|
44 | _actions = () |
---|
45 | |
---|
46 | |
---|
47 | # |
---|
48 | # ZMI |
---|
49 | # |
---|
50 | _properties = ( |
---|
51 | {'id': 'title', 'type': 'string', 'mode': 'w', |
---|
52 | 'label': 'Title'}, |
---|
53 | {'id': 'uni_id', 'type': 'string', 'mode': 'w', |
---|
54 | 'label': 'University ID'}, |
---|
55 | {'id': 'uni_name', 'type': 'string', 'mode': 'w', |
---|
56 | 'label': 'University Name'}, |
---|
57 | ) |
---|
58 | title = '' |
---|
59 | def __init__(self,uni_id,uni_name): |
---|
60 | self.manage_changeProperties(uni_id = uni_id, |
---|
61 | uni_name = uni_name, |
---|
62 | ) |
---|
63 | PortalFolder.__init__(self, self.id) |
---|
64 | |
---|
65 | |
---|
66 | def verifyFaculties(self, academics): ###( |
---|
67 | """install Universityspecific Faculies with Departments""" |
---|
68 | faculties = [ |
---|
69 | ## {'id': 'agri', ###( |
---|
70 | ## 'Title': 'Agriculture', |
---|
71 | ## 'departments': [ |
---|
72 | ## { 'id': 'dep1', ###( |
---|
73 | ## 'Title': 'One', |
---|
74 | ## }, |
---|
75 | ## ], |
---|
76 | ## },###) |
---|
77 | { 'id': 'science', |
---|
78 | 'Title': 'Science', |
---|
79 | 'departments': [ |
---|
80 | { 'id': 'bio', ###( |
---|
81 | 'Title': 'Biochemistry', |
---|
82 | }, |
---|
83 | { 'id': 'bot', |
---|
84 | 'Title': 'Botany', |
---|
85 | }, |
---|
86 | { 'id': 'che', |
---|
87 | 'Title': 'Chemistry', |
---|
88 | }, |
---|
89 | { 'id': 'com', |
---|
90 | 'Title': 'Computer Science', |
---|
91 | }, |
---|
92 | { 'id': 'geo', |
---|
93 | 'Title': 'Geologie', |
---|
94 | }, |
---|
95 | { 'id': 'mat', |
---|
96 | 'Title': 'Mathematics', |
---|
97 | }, |
---|
98 | { 'id': 'mic', |
---|
99 | 'Title': 'Microbiology', |
---|
100 | }, |
---|
101 | { 'id': 'opt', |
---|
102 | 'Title': 'Optometry', |
---|
103 | }, |
---|
104 | { 'id': 'phy', |
---|
105 | 'Title': 'Physics', |
---|
106 | }, |
---|
107 | { 'id': 'zoo', |
---|
108 | 'Title': 'Zoology', |
---|
109 | }, |
---|
110 | ], |
---|
111 | },###) |
---|
112 | ]###) |
---|
113 | #self.log('Verifying Faculties in %s' % academics.absolute_url(relative=1)) |
---|
114 | for faculty in faculties: |
---|
115 | fid = faculty['id'] |
---|
116 | f = getattr(academics,fid,None) |
---|
117 | #self.log('Checking Faculty %(id)s = %(Title)s' % faculty) |
---|
118 | if f is None: |
---|
119 | #self.log('Creating Faculty %(id)s = %(Title)s' % faculty) |
---|
120 | academics.invokeFactory('Faculty', fid) |
---|
121 | f = getattr(academics,fid) |
---|
122 | f.getContent().edit(mapping=faculty) |
---|
123 | for department in faculty['departments']: |
---|
124 | #self.log('Checking Department %(id)s = %(Title)s' % department) |
---|
125 | did = department['id'] |
---|
126 | d = getattr(f,did,None) |
---|
127 | if d is None: |
---|
128 | #self.log('Creating Department %(id)s = %(Title)s' % department) |
---|
129 | f.invokeFactory('Department', did) |
---|
130 | d = getattr(f,did) |
---|
131 | d.getContent().edit(mapping=department) |
---|
132 | ###) |
---|
133 | |
---|
134 | InitializeClass(WAeUPTool) |
---|
135 | |
---|
136 | def verifyPortlets(portal, portlets=(), object=None): ###( |
---|
137 | """Verify the existence of given portet in the object's portlet |
---|
138 | container. If not found, a portlet is instantiated. |
---|
139 | Existing portlets are not affected. |
---|
140 | 'portlets' is a tuple with the dictionaries given by the export tab |
---|
141 | as entries. |
---|
142 | The default object is the portal itself. |
---|
143 | return the list a new portlet ids. |
---|
144 | """ |
---|
145 | #self.log('Verifying portlets on %s' % object.absolute_url(relative=1)) |
---|
146 | #portlet_container = CPSInstaller.getPortletContainer(object, create=1) |
---|
147 | idpc = portal.portal_cpsportlets.getPortletContainerId() |
---|
148 | if not hasattr(object, idpc): |
---|
149 | ## self.log(" Creating %s/%s" % |
---|
150 | ## (object.absolute_url(relative=1), idpc)) |
---|
151 | object.manage_addProduct['CPSPortlets'].addPortletsContainer() |
---|
152 | portlet_container = getattr(object, idpc, None) |
---|
153 | ttool = portal.portal_types |
---|
154 | returned = [] |
---|
155 | for new_portlet in portlets: |
---|
156 | existing_portlets = portlet_container.listPortlets() |
---|
157 | updated = 0 |
---|
158 | # Check if the portlet needs an update |
---|
159 | identifier = new_portlet.get('identifier') |
---|
160 | if identifier: |
---|
161 | for portlet in existing_portlets: |
---|
162 | if identifier == portlet.identifier: |
---|
163 | #portal.log(" Update of portlet: %s" % portlet) |
---|
164 | portlet.edit(**new_portlet) |
---|
165 | portlet_id = portlet.getId() |
---|
166 | updated = 1 |
---|
167 | continue |
---|
168 | slot = new_portlet.get('slot') |
---|
169 | if slot: |
---|
170 | for portlet in existing_portlets: |
---|
171 | if slot == portlet.slot: |
---|
172 | #portal.log(" Update of portlet: %s" % portlet) |
---|
173 | portlet.edit(**new_portlet) |
---|
174 | portlet_id = portlet.getId() |
---|
175 | updated = 1 |
---|
176 | continue |
---|
177 | |
---|
178 | if not updated: |
---|
179 | #portal.log(" Creation of portlet: %s" % new_portlet) |
---|
180 | portlet_id = portal.portal_cpsportlets.createPortlet( |
---|
181 | ptype_id=new_portlet['type'], |
---|
182 | context=object, |
---|
183 | **new_portlet) |
---|
184 | if portlet_id not in returned: |
---|
185 | returned.append(portlet_id) |
---|
186 | return returned |
---|
187 | ###) |
---|
188 | |
---|
189 | addWAeUPToolForm = HTMLFile('zmi/manage_addWAeUPUniversity', |
---|
190 | globals()) |
---|
191 | |
---|
192 | def addWAeUPTool(container, id, |
---|
193 | title='WAeUP University', |
---|
194 | description='', |
---|
195 | langs_list=None, |
---|
196 | manager_id='manager', |
---|
197 | manager_sn='CPS', |
---|
198 | manager_givenName='Manager', |
---|
199 | manager_email='', |
---|
200 | manager_password='', |
---|
201 | manager_password_confirmation='', |
---|
202 | REQUEST=None): |
---|
203 | """Add WAeUPTool""" |
---|
204 | |
---|
205 | _log = [] |
---|
206 | def pr(bla, zlog=1, _log=_log): |
---|
207 | if bla == 'flush': |
---|
208 | return '<br/>\n'.join(_log) |
---|
209 | _log.append(bla) |
---|
210 | if (bla and zlog): |
---|
211 | LOG('addWAeUPUniversity:', INFO, bla) |
---|
212 | |
---|
213 | uni_id = id.strip() |
---|
214 | uni_name = title.strip() |
---|
215 | description = description.strip() |
---|
216 | manager_id = manager_id.strip() |
---|
217 | |
---|
218 | ## if not id: |
---|
219 | ## raise ValueError, "You have to provide an id for the portal!" |
---|
220 | ## if not manager_id: |
---|
221 | ## raise ValueError, "You have to provide an id for the CPS Administrator!" |
---|
222 | ## if not manager_email: |
---|
223 | ## raise ValueError, "You have to provide an email address for the CPS Administrator!" |
---|
224 | ## if not manager_password: |
---|
225 | ## raise ValueError, "You have to provide CPS Administrator password!" |
---|
226 | ## if manager_password != manager_password_confirmation: |
---|
227 | ## raise ValueError, "Password confirmation does not match password!" |
---|
228 | |
---|
229 | email_from_name = ('%s %s' % (manager_givenName, manager_sn)).strip() |
---|
230 | wt = WAeUPTool(uni_id,uni_name) |
---|
231 | id = wt.getId() |
---|
232 | container._setObject(id, wt) |
---|
233 | sections = getattr(container,'sections') |
---|
234 | workspaces = getattr(container,'workspaces') |
---|
235 | sections.invokeFactory('University',uni_id) |
---|
236 | uni = getattr(sections,uni_id) |
---|
237 | uni.getContent().edit(title=uni_name) |
---|
238 | uni.invokeFactory('StudentsFolder','students') |
---|
239 | students = getattr(uni,'students').getContent() |
---|
240 | students.edit(mapping={'Title':'Students'}) |
---|
241 | ## uni.folder_localrole_add(member_ids=('group:Students',), |
---|
242 | ## member_role='SectionReviewer', |
---|
243 | ## ) |
---|
244 | ## uni.content_create(type_name='AcademicsFolder',title='academics') |
---|
245 | ## sections.uni.folder_localrole_add(member_ids=('group:StudentManager',), |
---|
246 | ## member_role='SectionManager', |
---|
247 | ## ) |
---|
248 | ## uni.students.manage_setLocalGroupRoles(groupid = 'Students',roles=('Contributor',)) |
---|
249 | uni.invokeFactory('AcademicsFolder','academics', title='Academics') |
---|
250 | academics = getattr(uni,'academics').getContent() |
---|
251 | academics.edit(mapping={'Title':'Academics'}) |
---|
252 | uni.invokeFactory('AccoFolder','accommodation', title='Accommodation') |
---|
253 | accommodation = getattr(uni,'accommodation').getContent() |
---|
254 | accommodation.edit(mapping={'Title':'Accommodation'}) |
---|
255 | academics = getattr(uni,'academics',None) |
---|
256 | if academics is None: |
---|
257 | uni.invokeFactory('AcademicsFolder','academics') |
---|
258 | academics = getattr(uni,'academics') |
---|
259 | academics.getContent().edit(mapping={'Title':'Academics'}) |
---|
260 | wt.verifyFaculties(academics) |
---|
261 | if not hasattr(uni,'accommodation'): |
---|
262 | uni.invokeFactory('AccoFolder','accommodation') |
---|
263 | accommodation = getattr(uni,'accommodation').getContent() |
---|
264 | accommodation.edit(mapping={'Title':'Accommodation'}) |
---|
265 | #uni.manage_setLocalGroupRoles(groupid = 'role:Anonymous',roles=('SectionReader',)) |
---|
266 | # portlets ###( |
---|
267 | # |
---|
268 | portlets = ( |
---|
269 | {#'identifier': 'waeup_breadcrumbs', |
---|
270 | 'type': 'Breadcrumbs Portlet', |
---|
271 | 'slot': 'waeup_breadcrumbs', |
---|
272 | 'first_item': 0, |
---|
273 | 'display_site_root': 0, |
---|
274 | 'Title': 'waeup_breadcrumbs', |
---|
275 | 'display': 'horizontal_trail', |
---|
276 | 'display_hidden_folders': 0, |
---|
277 | 'order': 0, |
---|
278 | }, |
---|
279 | {#'identifier': 'waeup_main_tab_actions', |
---|
280 | 'type': 'Actions Portlet', |
---|
281 | 'slot': 'main_tabs', |
---|
282 | 'order': 0, |
---|
283 | 'categories': ['main_tabs',], |
---|
284 | 'Title': 'waep_main_tab_actions', |
---|
285 | }, |
---|
286 | {#'identifier': 'waeup_object_actions', |
---|
287 | 'type': 'Actions Portlet', |
---|
288 | 'slot': 'waeup_object_actions', |
---|
289 | 'order': 0, |
---|
290 | 'categories': ['object',], |
---|
291 | 'Title': 'waep_manager_actions', |
---|
292 | }, |
---|
293 | {#'identifier': 'waeup_left_top', |
---|
294 | 'type': 'Custom Portlet', |
---|
295 | 'slot': 'left_top', |
---|
296 | 'order': 0, |
---|
297 | 'render_method': 'portlet_session_info', |
---|
298 | 'Title': 'Session Info', |
---|
299 | }, |
---|
300 | ) |
---|
301 | #verifyPortletContainer(uni) |
---|
302 | verifyPortlets(container,portlets,uni) |
---|
303 | |
---|
304 | ###) |
---|
305 | if REQUEST is not None: |
---|
306 | url = container.absolute_url() |
---|
307 | REQUEST.RESPONSE.redirect('%s/manage_main' % url) |
---|
308 | |
---|