1 | #-*- mode: python; mode: fold -*- |
---|
2 | # $Id: install.py 197 2006-02-08 12:47:31Z joachim $ |
---|
3 | from Products.ExternalMethod.ExternalMethod import ExternalMethod |
---|
4 | from Products.CPSInstaller.CPSInstaller import CPSInstaller |
---|
5 | from Products.CMFCore.CMFCorePermissions import View, ModifyPortalContent,AccessContentsInformation |
---|
6 | from Products.WAeUP.WAeUPPermissions import UniversityManage, StudentManage,FacultyManage,\ |
---|
7 | DepartmentManage,CourseManage |
---|
8 | try: |
---|
9 | from Products.CPSSubscriptions.permissions import CanNotifyContent |
---|
10 | CPSSubscriptions = True |
---|
11 | except ImportError: |
---|
12 | CPSSubscriptions = False |
---|
13 | try: |
---|
14 | from Products.CPSForum.CPSForumPermissions import ForumManageComments |
---|
15 | CPSForum = True |
---|
16 | except ImportError: |
---|
17 | CPSForum = False |
---|
18 | |
---|
19 | from Products.WAeUP.Students import addStudentsFolder |
---|
20 | |
---|
21 | SRPP_ID = "demouni" |
---|
22 | SRPP_TITLE = "Demo University" |
---|
23 | |
---|
24 | class WAeUPInstaller(CPSInstaller): |
---|
25 | """ |
---|
26 | WAeUP Installer |
---|
27 | """ |
---|
28 | product_name = "WAeUP" |
---|
29 | |
---|
30 | def install(self,portal): |
---|
31 | "install" |
---|
32 | log = [] |
---|
33 | prlog = log.append |
---|
34 | |
---|
35 | def pr(msg, prlog=prlog): |
---|
36 | prlog('%s<br>' % msg) |
---|
37 | |
---|
38 | product_name = self.product_name |
---|
39 | pr("Starting %(product_name)s install" % vars() ) |
---|
40 | |
---|
41 | # Roles and Permissions ###( |
---|
42 | # |
---|
43 | self.verifyRoles(( |
---|
44 | # A role that can manage the University. |
---|
45 | 'UniversityManager', |
---|
46 | # A role that can manage the StudentsRecords. |
---|
47 | 'StudentManager', |
---|
48 | # A role that can manage a Faculty. |
---|
49 | 'FacultyManager', |
---|
50 | # A role that can manage a department. |
---|
51 | 'DepartmentManager', |
---|
52 | # A role that can manage a Course. |
---|
53 | 'CourseManager', |
---|
54 | # The Student Role |
---|
55 | 'Student', |
---|
56 | )) |
---|
57 | waeup_perms = { |
---|
58 | UniversityManage: |
---|
59 | ('Manager', 'SectionManager','UniversityManager', |
---|
60 | ), |
---|
61 | StudentManage: |
---|
62 | ('Manager', 'SectionManager','UniversityManager', 'StudentManager' |
---|
63 | ), |
---|
64 | FacultyManage: |
---|
65 | ('Manager', 'SectionManager','UniversityManager', 'FacultyManager' |
---|
66 | ), |
---|
67 | DepartmentManage: |
---|
68 | ('Manager', 'SectionManager','UniversityManager', 'DepartmentManager' |
---|
69 | ), |
---|
70 | CourseManage: |
---|
71 | ('Manager', 'SectionManager','UniversityManager', 'CourseManager' |
---|
72 | ), |
---|
73 | } |
---|
74 | self.setupPortalPermissions(waeup_perms) |
---|
75 | ###) |
---|
76 | |
---|
77 | # external methods ###( |
---|
78 | # |
---|
79 | ext_methods = ( { 'id': 'waeup_migrate', |
---|
80 | 'title': 'WAeUP (migrate from an earlier version)', |
---|
81 | 'script': 'WAeUP.install', |
---|
82 | 'method': 'migrate', |
---|
83 | 'protected': 1, |
---|
84 | }, |
---|
85 | ) |
---|
86 | portal_objectIds = portal.objectIds() |
---|
87 | for meth in ext_methods: |
---|
88 | method = meth['id'] |
---|
89 | if method in portal_objectIds: |
---|
90 | portal._delObject(method) |
---|
91 | pr('Creating %s External Method' % method) |
---|
92 | ext_method = ExternalMethod(method, |
---|
93 | meth['title'], |
---|
94 | meth['script'], |
---|
95 | meth['method']) |
---|
96 | portal._setObject(method, ext_method) |
---|
97 | if method in portal_objectIds: |
---|
98 | manage_perms = portal[method].manage_permission |
---|
99 | if meth['protected']: |
---|
100 | pr("Protecting %s" % method) |
---|
101 | manage_perms(View, roles=['Manager'], acquire=0) |
---|
102 | manage_perms(AccessContentsInformation, roles=['Manager'], acquire=0) |
---|
103 | else: |
---|
104 | manage_perms(View, roles=['Manager'], acquire=1) |
---|
105 | ###) |
---|
106 | |
---|
107 | ########################################## |
---|
108 | # Actions |
---|
109 | ########################################## |
---|
110 | waeup_ptypes = "'University','StudentsFolder','Student','Jamb','Faculty','Department','Course'" |
---|
111 | waeup_ptypes += ",'AccoFolder','Accommodation','StudentPersonal','AcademicsFolder'" |
---|
112 | waeup_ptypes += ",'StudyLevel','Semester','CourseTicket','StudentDocuments','StudentEligibility'" |
---|
113 | if CPSSubscriptions: ###( |
---|
114 | |
---|
115 | ptypes = "('Portal', 'CPSMailAccess Message', 'CPSMailAccess Box', 'CPSMailAccess Folder',"\ |
---|
116 | + waeup_ptypes + ")" |
---|
117 | condition = "object.portal_type not in %s" % ptypes |
---|
118 | |
---|
119 | action = {'id' : 'notify_content', |
---|
120 | 'name' : 'action_notify_content', |
---|
121 | 'action' : 'string:${object_url}/content_notify_email_form', |
---|
122 | 'condition' : 'python:%s' % condition, |
---|
123 | 'permission' : (CanNotifyContent,), |
---|
124 | 'category' : 'object', |
---|
125 | } |
---|
126 | self.deleteActions({'portal_subscriptions': ['notify_content',]}) |
---|
127 | self.verifyAction('portal_subscriptions', **action) |
---|
128 | if CPSForum: |
---|
129 | condition = "object.portal_type not in (%s)" % waeup_ptypes |
---|
130 | |
---|
131 | action = {'id' : 'activate_comments', |
---|
132 | 'name': 'action_activate_comments', |
---|
133 | 'action': 'string:${object/absolute_url}/set_comment_mode?mode=1', |
---|
134 | 'condition' : 'python:%s' % condition, |
---|
135 | 'permission': (ForumManageComments,), |
---|
136 | 'category' : 'object', |
---|
137 | } |
---|
138 | self.deleteActions({'portal_subscriptions': ['activate_comments',]}) |
---|
139 | self.verifyAction('portal_subscriptions', **action) |
---|
140 | # now portal_discussion |
---|
141 | self.deleteActions({'portal_discussion': ['comment', |
---|
142 | 'activate_comments', |
---|
143 | 'deactivate_comments', |
---|
144 | 'manage_comments']}) |
---|
145 | action = {'id' : 'comment', |
---|
146 | 'name': 'action_comment', |
---|
147 | 'action': "string:${object/absolute_url}/post_comment", |
---|
148 | 'condition' : "python:getattr(object.getContent(), 'allow_discussion' , None) and object.hasCommentAction()", |
---|
149 | 'permission': (View,), |
---|
150 | 'category' : 'object', |
---|
151 | } |
---|
152 | self.verifyAction('portal_discussion', **action) |
---|
153 | action = {'id' : 'activate_comments', |
---|
154 | 'name': 'action_activate_comments', |
---|
155 | 'action': "string:${object/absolute_url}/set_comment_mode?mode=1", |
---|
156 | 'condition' : "python:getattr(object.getTypeInfo(),'cps_proxy_type','') in ('document', 'folderishdocument') and getattr(object.getContent(), 'allow_discussion' , None) == 1", |
---|
157 | 'permission': (ForumManageComments,), |
---|
158 | 'category' : 'object', |
---|
159 | } |
---|
160 | self.verifyAction('portal_discussion', **action) |
---|
161 | action = {'id' : 'deactivate_comments', |
---|
162 | 'name': 'action_deactivate_comments', |
---|
163 | 'action': "string:${object/absolute_url}/set_comment_mode?mode=0", |
---|
164 | 'condition' : "python:getattr(object.getTypeInfo(),'cps_proxy_type','') in ('document', 'folderishdocument') and getattr(object.getContent(), 'allow_discussion' , None) == 1", |
---|
165 | 'permission': (ForumManageComments,), |
---|
166 | 'category' : 'object', |
---|
167 | } |
---|
168 | self.verifyAction('portal_discussion', **action) |
---|
169 | action = {'id' : 'manage_comments', |
---|
170 | 'name': 'action_manage_comments', |
---|
171 | 'action': "string:${object/absolute_url}/manage_comment", |
---|
172 | 'condition' : "python:getattr(object.getTypeInfo(),'cps_proxy_type','') in ('document', 'folderishdocument') and getattr(object.getContent(), 'allow_discussion' , None) == 1", |
---|
173 | 'permission': (ForumManageComments,), |
---|
174 | 'category' : 'object', |
---|
175 | } |
---|
176 | self.verifyAction('portal_discussion', **action) |
---|
177 | |
---|
178 | ###) |
---|
179 | |
---|
180 | ########################################## |
---|
181 | # main_tab actions ###( |
---|
182 | ########################################## |
---|
183 | path = "/sections/%(SRPP_ID)s" % globals() |
---|
184 | actions = ( { 'tool' : 'portal_actions', |
---|
185 | 'id' : 'student_administration', |
---|
186 | 'name' : 'Students', |
---|
187 | 'action' : "python: portal.portal_url.getUrlFromRpath('sections/demouni/students')", |
---|
188 | #'action' : 'string:$portal_url%(path)s/students' % vars(), |
---|
189 | 'permission': (View, ), |
---|
190 | 'category' : 'main_tabs', |
---|
191 | 'visible' : 1, |
---|
192 | }, |
---|
193 | { 'tool' : 'portal_actions', |
---|
194 | 'id' : 'academics', |
---|
195 | 'name' : 'Academics', |
---|
196 | 'action' : "python: portal.portal_url.getUrlFromRpath('sections/demouni/academics')", |
---|
197 | #'action' : 'string:${portal_url}/academics', |
---|
198 | 'permission': (UniversityManage), |
---|
199 | 'category' : 'main_tabs', |
---|
200 | 'visible' : 1, |
---|
201 | }, |
---|
202 | { 'tool' : 'portal_actions', |
---|
203 | 'id' : 'accomodation', |
---|
204 | 'name' : 'Accommodation', |
---|
205 | 'action' : "python: portal.portal_url.getUrlFromRpath('sections/demouni/accommodation')", |
---|
206 | #'action' : 'string:${portal_url}/accommodation', |
---|
207 | 'permissions': (UniversityManage), |
---|
208 | #'permissions': (ModifyPortalContent,UniversityManage,StudentManage), |
---|
209 | 'category' : 'main_tabs', |
---|
210 | 'visible' : 1, |
---|
211 | }, |
---|
212 | { 'tool' : 'portal_actions', |
---|
213 | 'id' : 'chat', |
---|
214 | 'name' : 'Chat', |
---|
215 | 'action' : "python: portal.portal_url.getUrlFromRpath('sections/demouni/chat')", |
---|
216 | #'action' : 'string:${portal_url}/accommodation', |
---|
217 | 'permissions': (View), |
---|
218 | #'permissions': (ModifyPortalContent,UniversityManage,StudentManage), |
---|
219 | 'category' : 'main_tabs', |
---|
220 | 'visible' : 1, |
---|
221 | }, |
---|
222 | ## { 'tool' : 'portal_actions', ###( |
---|
223 | ## 'id' : 'add_jamb', |
---|
224 | ## 'name' : 'Add Student JAMB', |
---|
225 | ## 'action' : 'string:${object/absolute_url}/create_jamb', |
---|
226 | ## 'permission': (), |
---|
227 | ## 'condition' : 'python: member and here.portal_type in ("StudentsFolder",) and "StudentManager" in member.getGroups()', |
---|
228 | ## 'category' : 'student', |
---|
229 | ## 'visible' : 1, |
---|
230 | ## }, |
---|
231 | ## { 'tool' : 'portal_actions', |
---|
232 | ## 'id' : 'add_faculty', |
---|
233 | ## 'name' : 'Add New Faculty', |
---|
234 | ## 'action' : 'string:${object/absolute_url}/addFaculty', |
---|
235 | ## 'permission': (), |
---|
236 | ## 'condition' : 'python: member and here.portal_type in ("University",) and "StudentManager" in member.getGroups()', |
---|
237 | ## 'category' : 'student', |
---|
238 | ## 'visible' : 1, |
---|
239 | ## }, |
---|
240 | ## { 'tool' : 'portal_actions', |
---|
241 | ## 'id' : 'add_department', |
---|
242 | ## 'name' : 'Add New Department', |
---|
243 | ## 'action' : 'string:${object/absolute_url}/addDepartment', |
---|
244 | ## 'permission': (), |
---|
245 | ## 'condition' : 'python: member and here.portal_type in ("Faculty",) and "StudentManager" in member.getGroups()', |
---|
246 | ## 'category' : 'student', |
---|
247 | ## 'visible' : 1, |
---|
248 | ## }, |
---|
249 | ## { 'tool' : 'portal_actions', |
---|
250 | ## 'id' : 'add_course', |
---|
251 | ## 'name' : 'Add New Course', |
---|
252 | ## 'action' : 'string:${object/absolute_url}/addCourse', |
---|
253 | ## 'permission': (), |
---|
254 | ## 'condition' : 'python: member and here.portal_type in ("Department",) and "StudentManager" in member.getGroups()', |
---|
255 | ## 'category' : 'student', |
---|
256 | ## 'visible' : 1, |
---|
257 | ## }, |
---|
258 | ## { 'tool' : 'portal_actions', |
---|
259 | ## 'id' : 'add_personal', |
---|
260 | ## 'name' : 'Add personal Data', |
---|
261 | ## 'action' : 'string:${object/absolute_url}/create_personal_form', |
---|
262 | ## 'permission': (), |
---|
263 | ## 'condition' : 'python: 0 and member and not here.portal_type in ("Jamb","StudentsFolder") and not "StudentManager" in member.getGroups()', |
---|
264 | ## 'category' : 'student', |
---|
265 | ## 'visible' : 1, |
---|
266 | ## }, |
---|
267 | ## { 'tool' : 'portal_actions', |
---|
268 | ## 'id' : 'edit_jamb', |
---|
269 | ## 'name' : 'Edit Jamb Data', |
---|
270 | ## 'action' : 'cpsdocument_edit_form', |
---|
271 | ## 'permission': ( ), |
---|
272 | ## 'condition' : 'python: member and here.portal_type in ("Student",) and "StudentManager" in member.getGroups()', |
---|
273 | ## 'category' : 'student', |
---|
274 | ## 'visible' : 1, |
---|
275 | ## }, |
---|
276 | ###) |
---|
277 | |
---|
278 | ) |
---|
279 | self.deleteActions({'portal_actions': [action['id'] for action in actions]}) |
---|
280 | self.verifyActions(actions) |
---|
281 | ########################################## |
---|
282 | ###) |
---|
283 | |
---|
284 | # skins |
---|
285 | ########################################## |
---|
286 | pr("Verifying %(product_name)s skinss" % vars()) |
---|
287 | wskins = { 'waeup_default' : 'Products/WAeUP/skins/waeup_default', |
---|
288 | 'waeup_faculty' : 'Products/WAeUP/skins/waeup_faculty', |
---|
289 | 'waeup_student' : 'Products/WAeUP/skins/waeup_student', |
---|
290 | } |
---|
291 | self.verifySkins(wskins) |
---|
292 | self.resetSkinCache() |
---|
293 | |
---|
294 | # Themes ###( |
---|
295 | # |
---|
296 | # Importing portal themes |
---|
297 | ## theme_container = getattr(portal, 'portal_themes') |
---|
298 | ## # the first theme in each category is the default theme. |
---|
299 | ## themes_list = {'WAeUP': ({'id': 'waeup_plain_theme', |
---|
300 | ## 'file': 'waeup_plain_theme.zexp', |
---|
301 | ## }, |
---|
302 | ## {'id': 'waeup_management_theme', |
---|
303 | ## 'file': 'waeup_management_theme.zexp', |
---|
304 | ## }, |
---|
305 | ## ), |
---|
306 | ## } |
---|
307 | ## |
---|
308 | ## |
---|
309 | ## theme_ids = theme_container.objectIds() |
---|
310 | ## theme_container.manage_delObjects(theme_ids) |
---|
311 | ## target_themes = themes_list[Target] |
---|
312 | ## for theme in target_themes: |
---|
313 | ## pr(" Importing %s theme" % theme['id']) |
---|
314 | ## zexppath = os.path.join(zexpdir, theme['file']) |
---|
315 | ## try: |
---|
316 | ## theme_container._importObjectFromFile(zexppath) |
---|
317 | ## except: |
---|
318 | ## pr(" Could not import theme %s" % theme['id']) |
---|
319 | ## |
---|
320 | ## # set the first theme in the list as the default one. |
---|
321 | ## theme_container.setDefaultTheme(target_themes[0]['id']) |
---|
322 | ###) |
---|
323 | |
---|
324 | |
---|
325 | ########################################## |
---|
326 | # portal types |
---|
327 | ########################################## |
---|
328 | dtypes = portal.getWAeUPTypes() |
---|
329 | self.verifyFlexibleTypes(dtypes) |
---|
330 | self.allowContentTypes('University', ('Workspace','Section',)) |
---|
331 | ########################################## |
---|
332 | # Schemas |
---|
333 | ########################################## |
---|
334 | pr("Verifying %(product_name)s schemas" % vars()) |
---|
335 | self.verifySchemas(portal.getWAeUPSchemas()) |
---|
336 | ########################################## |
---|
337 | # widgets |
---|
338 | ########################################## |
---|
339 | pr("Verifying %(product_name)s widgets" % vars()) |
---|
340 | self.verifyWidgets(portal.getWAeUPWidgets()) |
---|
341 | ########################################## |
---|
342 | # layouts |
---|
343 | ########################################## |
---|
344 | pr("Verifying %(product_name)s layouts" % vars()) |
---|
345 | self.verifyLayouts(portal.getWAeUPLayouts()) |
---|
346 | ########################################## |
---|
347 | # Vocabularies |
---|
348 | ########################################## |
---|
349 | pr("Verifying %(product_name)s vocabularies" % vars()) |
---|
350 | self.verifyVocabularies(portal.getWAeUPVocabularies()) |
---|
351 | ########################################## |
---|
352 | # Groups |
---|
353 | ########################################## |
---|
354 | |
---|
355 | self.installCustomWorkflows() |
---|
356 | self.verifyWorkflowAssociation() |
---|
357 | |
---|
358 | pr("End of specific %(product_name)s install" % vars()) |
---|
359 | #return '\n'.join(log) |
---|
360 | self.finalize() |
---|
361 | |
---|
362 | def verifyPortlets(self, portlets=(), object=None): ###( |
---|
363 | """Verify the existence of given portet in the object's portlet |
---|
364 | container. If not found, a portlet is instantiated. |
---|
365 | Existing portlets are not affected. |
---|
366 | |
---|
367 | 'portlets' is a tuple with the dictionaries given by the export tab |
---|
368 | as entries. |
---|
369 | The default object is the portal itself. |
---|
370 | |
---|
371 | return the list a new portlet ids. |
---|
372 | """ |
---|
373 | |
---|
374 | if object is None: |
---|
375 | object = self.portal |
---|
376 | |
---|
377 | self.log('Verifying portlets on %s' % object.absolute_url(relative=1)) |
---|
378 | |
---|
379 | portlet_container = self.getPortletContainer(object, create=1) |
---|
380 | |
---|
381 | ttool = self.getTool('portal_types') |
---|
382 | |
---|
383 | returned = [] |
---|
384 | for new_portlet in portlets: |
---|
385 | existing_portlets = portlet_container.listPortlets() |
---|
386 | updated = 0 |
---|
387 | |
---|
388 | # Check if the portlet needs an update |
---|
389 | identifier = new_portlet.get('identifier') |
---|
390 | if identifier: |
---|
391 | for portlet in existing_portlets: |
---|
392 | if identifier == portlet.identifier: |
---|
393 | self.log(" Update of portlet: %s" % portlet) |
---|
394 | portlet.edit(**new_portlet) |
---|
395 | portlet_id = portlet.getId() |
---|
396 | updated = 1 |
---|
397 | continue |
---|
398 | slot = new_portlet.get('slot') |
---|
399 | if slot: |
---|
400 | for portlet in existing_portlets: |
---|
401 | if slot == portlet.slot: |
---|
402 | self.log(" Update of portlet: %s" % portlet) |
---|
403 | portlet.edit(**new_portlet) |
---|
404 | portlet_id = portlet.getId() |
---|
405 | updated = 1 |
---|
406 | continue |
---|
407 | |
---|
408 | if not updated: |
---|
409 | self.log(" Creation of portlet: %s" % new_portlet) |
---|
410 | portlet_id = self.portal.portal_cpsportlets.createPortlet( |
---|
411 | ptype_id=new_portlet['type'], |
---|
412 | context=object, |
---|
413 | **new_portlet) |
---|
414 | if portlet_id not in returned: |
---|
415 | returned.append(portlet_id) |
---|
416 | return returned |
---|
417 | ###) |
---|
418 | |
---|
419 | |
---|
420 | def installCustomWorkflows(self): ###( |
---|
421 | """Installs custom workflows |
---|
422 | """ |
---|
423 | from Products.WAeUP.Workflows.WAeUPWorkflow import \ |
---|
424 | waeupWorkflowsInstall |
---|
425 | |
---|
426 | waeupWorkflowsInstall(self.context) |
---|
427 | |
---|
428 | ###) |
---|
429 | |
---|
430 | def verifyWorkflowAssociation(self): ###( |
---|
431 | """Verify workflow association |
---|
432 | """ |
---|
433 | ws_chains = { |
---|
434 | 'Student': 'waeup_workspace_wf', |
---|
435 | 'Jamb': 'waeup_workspace_wf', |
---|
436 | } |
---|
437 | |
---|
438 | se_chains = { 'University': 'waeup_section_wf', |
---|
439 | 'AcademicsFolder': 'waeup_section_wf', |
---|
440 | 'StudentsFolder': 'waeup_student_wf', |
---|
441 | 'Student': 'waeup_student_wf', |
---|
442 | 'StudentPersonal': 'waeup_student_wf', |
---|
443 | 'StudentEligibility': 'waeup_student_wf', |
---|
444 | 'StudentDocuments': 'waeup_student_wf', |
---|
445 | 'Jamb': 'waeup_section_wf', |
---|
446 | 'ScratchCard': 'waeup_section_wf', |
---|
447 | 'Faculty': 'waeup_section_wf', |
---|
448 | 'Department': 'waeup_section_wf', |
---|
449 | 'Course': 'waeup_section_wf', |
---|
450 | 'StudyLevel': 'waeup_student_wf', |
---|
451 | 'Semester': 'waeup_student_wf', |
---|
452 | 'CourseTicket': 'waeup_student_wf', |
---|
453 | 'AccoFolder': 'waeup_section_wf', |
---|
454 | 'Accommodation': 'waeup_section_wf', |
---|
455 | } |
---|
456 | |
---|
457 | self.verifyLocalWorkflowChains(self.portal['workspaces'], |
---|
458 | ws_chains, |
---|
459 | destructive=1) |
---|
460 | self.verifyLocalWorkflowChains(self.portal['sections'], |
---|
461 | se_chains, |
---|
462 | destructive=1) |
---|
463 | ###) |
---|
464 | |
---|
465 | def verifyFaculties(self, academics): ###( |
---|
466 | """install Universityspecific Faculies with Departments""" |
---|
467 | faculties = [ |
---|
468 | ## {'id': 'agri', ###( |
---|
469 | ## 'Title': 'Agriculture', |
---|
470 | ## 'departments': [ |
---|
471 | ## { 'id': 'dep1', ###( |
---|
472 | ## 'Title': 'One', |
---|
473 | ## }, |
---|
474 | ## ], |
---|
475 | ## },###) |
---|
476 | { 'id': 'science', |
---|
477 | 'Title': 'Science', |
---|
478 | 'departments': [ |
---|
479 | { 'id': 'bio', ###( |
---|
480 | 'Title': 'Biochemistry', |
---|
481 | }, |
---|
482 | { 'id': 'bot', |
---|
483 | 'Title': 'Botany', |
---|
484 | }, |
---|
485 | { 'id': 'che', |
---|
486 | 'Title': 'Chemistry', |
---|
487 | }, |
---|
488 | { 'id': 'com', |
---|
489 | 'Title': 'Computer Science', |
---|
490 | }, |
---|
491 | { 'id': 'geo', |
---|
492 | 'Title': 'Geologie', |
---|
493 | }, |
---|
494 | { 'id': 'mat', |
---|
495 | 'Title': 'Mathematics', |
---|
496 | }, |
---|
497 | { 'id': 'mic', |
---|
498 | 'Title': 'Microbiology', |
---|
499 | }, |
---|
500 | { 'id': 'opt', |
---|
501 | 'Title': 'Optometry', |
---|
502 | }, |
---|
503 | { 'id': 'phy', |
---|
504 | 'Title': 'Physics', |
---|
505 | }, |
---|
506 | { 'id': 'zoo', |
---|
507 | 'Title': 'Zoology', |
---|
508 | }, |
---|
509 | ], |
---|
510 | },###) |
---|
511 | ]###) |
---|
512 | self.log('Verifying Faculties in %s' % academics.absolute_url(relative=1)) |
---|
513 | for faculty in faculties: |
---|
514 | fid = faculty['id'] |
---|
515 | f = getattr(academics,fid,None) |
---|
516 | self.log('Checking Faculty %(id)s = %(Title)s' % faculty) |
---|
517 | if f is None: |
---|
518 | self.log('Creating Faculty %(id)s = %(Title)s' % faculty) |
---|
519 | academics.invokeFactory('Faculty', fid) |
---|
520 | f = getattr(academics,fid) |
---|
521 | f.getContent().edit(mapping=faculty) |
---|
522 | for department in faculty['departments']: |
---|
523 | self.log('Checking Department %(id)s = %(Title)s' % department) |
---|
524 | did = department['id'] |
---|
525 | d = getattr(f,did,None) |
---|
526 | if d is None: |
---|
527 | self.log('Creating Department %(id)s = %(Title)s' % department) |
---|
528 | f.invokeFactory('Department', did) |
---|
529 | d = getattr(f,did) |
---|
530 | d.getContent().edit(mapping=department) |
---|
531 | ###) |
---|
532 | |
---|
533 | |
---|
534 | |
---|
535 | def install(self): ###( |
---|
536 | installer = WAeUPInstaller(self) |
---|
537 | installer.install(self) |
---|
538 | #dirtool = getattr(self,'portal_directories') |
---|
539 | return installer.logResult() |
---|
540 | groups = dirtool.groups |
---|
541 | for delEntry in ('StudentManager',): |
---|
542 | if delEntry in groups.listEntryIds(): |
---|
543 | groups.deleteEntry(delEntry) |
---|
544 | for newEntry in ('Students',): |
---|
545 | if newEntry not in groups.listEntryIds(): |
---|
546 | groups.createEntry({'group': newEntry, |
---|
547 | 'members': []}) |
---|
548 | #groups.manage_setLocalGroupRoles(groupid = 'StudentManager',roles=('Manager',)) |
---|
549 | #groups.manage_setLocalGroupRoles(groupid = 'Students',roles=('Contributor',)) |
---|
550 | sections = getattr(self,'sections') |
---|
551 | waeup = getattr(sections,SRPP_ID,None) |
---|
552 | if not waeup: |
---|
553 | sections.invokeFactory('University',SRPP_ID) |
---|
554 | waeup = getattr(sections,SRPP_ID) |
---|
555 | waeup.getContent().edit(mapping={'Title':SRPP_TITLE}) |
---|
556 | waeup.folder_localrole_add(member_ids=('group:Students',), |
---|
557 | member_role='SectionReviewer', |
---|
558 | ) |
---|
559 | waeup.invokeFactory('StudentsFolder','students') |
---|
560 | students = getattr(waeup,'students').getContent() |
---|
561 | students.edit(mapping={'Title':'Students'}) |
---|
562 | waeup.folder_localrole_add(member_ids=('group:Students',), |
---|
563 | member_role='SectionReviewer', |
---|
564 | ) |
---|
565 | ## waeup.content_create(type_name='AcademicsFolder',title='academics') |
---|
566 | ## sections.waeup.folder_localrole_add(member_ids=('group:StudentManager',), |
---|
567 | ## member_role='SectionManager', |
---|
568 | ## ) |
---|
569 | waeup.students.manage_setLocalGroupRoles(groupid = 'Students',roles=('Contributor',)) |
---|
570 | waeup.invokeFactory('AcademicsFolder','academics', title='Academics') |
---|
571 | academics = getattr(waeup,'academics').getContent() |
---|
572 | academics.edit(mapping={'Title':'Academics'}) |
---|
573 | waeup.invokeFactory('AccoFolder','accommodation', title='Accommodation') |
---|
574 | accommodation = getattr(waeup,'accommodation').getContent() |
---|
575 | accommodation.edit(mapping={'Title':'Accommodation'}) |
---|
576 | academics = getattr(waeup,'academics',None) |
---|
577 | if academics is None: |
---|
578 | waeup.invokeFactory('AcademicsFolder','academics') |
---|
579 | academics = getattr(waeup,'academics') |
---|
580 | academics.getContent().edit(mapping={'Title':'Academics'}) |
---|
581 | installer.verifyFaculties(academics) |
---|
582 | if not hasattr(waeup,'accommodation'): |
---|
583 | waeup.invokeFactory('AccoFolder','accommodation') |
---|
584 | accommodation = getattr(waeup,'accommodation').getContent() |
---|
585 | accommodation.edit(mapping={'Title':'Accommodation'}) |
---|
586 | waeup.manage_setLocalGroupRoles(groupid = 'role:Anonymous',roles=('SectionReader',)) |
---|
587 | # portlets ###( |
---|
588 | # |
---|
589 | portlets = ( |
---|
590 | ## {'identifier': 'waeup_main_tabs', |
---|
591 | ## 'type': 'Custom Portlet', |
---|
592 | ## 'slot': 'main_tabs', |
---|
593 | ## 'order': 0, |
---|
594 | ## 'render_method': 'portlet_main_navigation', |
---|
595 | ## 'Title': 'main tabs', |
---|
596 | ## }, |
---|
597 | {#'identifier': 'waeup_breadcrumbs', |
---|
598 | 'type': 'Breadcrumbs Portlet', |
---|
599 | 'slot': 'waeup_breadcrumbs', |
---|
600 | 'first_item': 0, |
---|
601 | 'display_site_root': 0, |
---|
602 | 'Title': 'waeup_breadcrumbs', |
---|
603 | 'display': 'horizontal_trail', |
---|
604 | 'display_hidden_folders': 0, |
---|
605 | 'order': 0, |
---|
606 | }, |
---|
607 | {#'identifier': 'waeup_main_tab_actions', |
---|
608 | 'type': 'Actions Portlet', |
---|
609 | 'slot': 'main_tabs', |
---|
610 | 'order': 0, |
---|
611 | 'categories': ['main_tabs',], |
---|
612 | 'Title': 'waep_main_tab_actions', |
---|
613 | }, |
---|
614 | {#'identifier': 'waeup_object_actions', |
---|
615 | 'type': 'Actions Portlet', |
---|
616 | 'slot': 'waeup_object_actions', |
---|
617 | 'order': 0, |
---|
618 | 'categories': ['object',], |
---|
619 | 'Title': 'waep_manager_actions', |
---|
620 | }, |
---|
621 | {#'identifier': 'waeup_left_top', |
---|
622 | 'type': 'Custom Portlet', |
---|
623 | 'slot': 'left_top', |
---|
624 | 'order': 0, |
---|
625 | 'render_method': 'portlet_session_info', |
---|
626 | 'Title': 'Session Info', |
---|
627 | }, |
---|
628 | ) |
---|
629 | installer.verifyPortletContainer(waeup) |
---|
630 | installer.verifyPortlets(portlets,waeup) |
---|
631 | |
---|
632 | ###) |
---|
633 | return installer.logResult() |
---|
634 | ###) |
---|
635 | |
---|
636 | def migrate(self): ###( |
---|
637 | "update data" |
---|
638 | log = [] |
---|
639 | prlog = log.append |
---|
640 | |
---|
641 | def pr(msg, prlog=prlog): |
---|
642 | prlog('%s' % msg) |
---|
643 | |
---|
644 | sections = getattr(self,'sections') |
---|
645 | waeup = getattr(sections,SRPP_ID,None) |
---|
646 | pr( "Start migrate") |
---|
647 | pr("migrating Students") |
---|
648 | students = getattr(waeup,'students') |
---|
649 | pr("migrating courses") |
---|
650 | academics = getattr(waeup,'academics') |
---|
651 | for fac in [getattr(academics,f.id) for f in academics.contentValues(filter={'portal_type': ('Faculty',)})]: |
---|
652 | pr("Faculty: %s" % fac.title_or_id()) |
---|
653 | for dep in [getattr(fac,d.id) for d in fac.contentValues(filter={'portal_type': ('Department',)})]: |
---|
654 | pr("Department: %s" % dep.title_or_id()) |
---|
655 | for course in [getattr(dep,c.id) for c in dep.contentValues(filter={'portal_type': ('Course',)})]: |
---|
656 | pr("Course: %s" % course.title_or_id()) |
---|
657 | content = course.getContent() |
---|
658 | heading = getattr(content,'heading',course.id) |
---|
659 | pr("heading = %(heading)s" % vars()) |
---|
660 | content.edit(mapping={'Title': heading}) |
---|
661 | pr("migrating halls") |
---|
662 | for ac in [getattr(waeup,a.id) for a in waeup.contentValues(filter={'portal_type': ('AccoFolder',)})]: |
---|
663 | for hall in [getattr(ac,h.id) for h in ac.contentValues(filter={'portal_type': ('Accommodation',)})]: |
---|
664 | pr("Hall: %s" % hall.title_or_id()) |
---|
665 | content = hall.getContent() |
---|
666 | heading = getattr(content,'heading',hall.id) |
---|
667 | pr("heading = %(heading)s" % vars()) |
---|
668 | content.edit(mapping={'Title': heading}) |
---|
669 | return '\n'.join(log) |
---|
670 | |
---|
671 | ###) |
---|
672 | |
---|