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