1 | #-*- mode: python; mode: fold -*- |
---|
2 | # $Id: install.py 179 2005-11-16 16:44:13Z 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'" |
---|
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' : 'add_jamb', |
---|
214 | ## 'name' : 'Add Student JAMB', |
---|
215 | ## 'action' : 'string:${object/absolute_url}/create_jamb', |
---|
216 | ## 'permission': (), |
---|
217 | ## 'condition' : 'python: member and here.portal_type in ("StudentsFolder",) and "StudentManager" in member.getGroups()', |
---|
218 | ## 'category' : 'student', |
---|
219 | ## 'visible' : 1, |
---|
220 | ## }, |
---|
221 | ## { 'tool' : 'portal_actions', |
---|
222 | ## 'id' : 'add_faculty', |
---|
223 | ## 'name' : 'Add New Faculty', |
---|
224 | ## 'action' : 'string:${object/absolute_url}/addFaculty', |
---|
225 | ## 'permission': (), |
---|
226 | ## 'condition' : 'python: member and here.portal_type in ("University",) and "StudentManager" in member.getGroups()', |
---|
227 | ## 'category' : 'student', |
---|
228 | ## 'visible' : 1, |
---|
229 | ## }, |
---|
230 | ## { 'tool' : 'portal_actions', |
---|
231 | ## 'id' : 'add_department', |
---|
232 | ## 'name' : 'Add New Department', |
---|
233 | ## 'action' : 'string:${object/absolute_url}/addDepartment', |
---|
234 | ## 'permission': (), |
---|
235 | ## 'condition' : 'python: member and here.portal_type in ("Faculty",) and "StudentManager" in member.getGroups()', |
---|
236 | ## 'category' : 'student', |
---|
237 | ## 'visible' : 1, |
---|
238 | ## }, |
---|
239 | ## { 'tool' : 'portal_actions', |
---|
240 | ## 'id' : 'add_course', |
---|
241 | ## 'name' : 'Add New Course', |
---|
242 | ## 'action' : 'string:${object/absolute_url}/addCourse', |
---|
243 | ## 'permission': (), |
---|
244 | ## 'condition' : 'python: member and here.portal_type in ("Department",) and "StudentManager" in member.getGroups()', |
---|
245 | ## 'category' : 'student', |
---|
246 | ## 'visible' : 1, |
---|
247 | ## }, |
---|
248 | ## { 'tool' : 'portal_actions', |
---|
249 | ## 'id' : 'add_personal', |
---|
250 | ## 'name' : 'Add personal Data', |
---|
251 | ## 'action' : 'string:${object/absolute_url}/create_personal_form', |
---|
252 | ## 'permission': (), |
---|
253 | ## 'condition' : 'python: 0 and member and not here.portal_type in ("Jamb","StudentsFolder") and not "StudentManager" in member.getGroups()', |
---|
254 | ## 'category' : 'student', |
---|
255 | ## 'visible' : 1, |
---|
256 | ## }, |
---|
257 | ## { 'tool' : 'portal_actions', |
---|
258 | ## 'id' : 'edit_jamb', |
---|
259 | ## 'name' : 'Edit Jamb Data', |
---|
260 | ## 'action' : 'cpsdocument_edit_form', |
---|
261 | ## 'permission': ( ), |
---|
262 | ## 'condition' : 'python: member and here.portal_type in ("Student",) and "StudentManager" in member.getGroups()', |
---|
263 | ## 'category' : 'student', |
---|
264 | ## 'visible' : 1, |
---|
265 | ## }, |
---|
266 | ###) |
---|
267 | |
---|
268 | ) |
---|
269 | self.deleteActions({'portal_actions': [action['id'] for action in actions]}) |
---|
270 | self.verifyActions(actions) |
---|
271 | ########################################## |
---|
272 | ###) |
---|
273 | |
---|
274 | # skins |
---|
275 | ########################################## |
---|
276 | pr("Verifying %(product_name)s skinss" % vars()) |
---|
277 | wskins = { 'waeup_default' : 'Products/WAeUP/skins/waeup_default', |
---|
278 | 'waeup_faculty' : 'Products/WAeUP/skins/waeup_faculty', |
---|
279 | 'waeup_student' : 'Products/WAeUP/skins/waeup_student', |
---|
280 | } |
---|
281 | self.verifySkins(wskins) |
---|
282 | self.resetSkinCache() |
---|
283 | |
---|
284 | # Themes ###( |
---|
285 | # |
---|
286 | # Importing portal themes |
---|
287 | ## theme_container = getattr(portal, 'portal_themes') |
---|
288 | ## # the first theme in each category is the default theme. |
---|
289 | ## themes_list = {'WAeUP': ({'id': 'waeup_plain_theme', |
---|
290 | ## 'file': 'waeup_plain_theme.zexp', |
---|
291 | ## }, |
---|
292 | ## {'id': 'waeup_management_theme', |
---|
293 | ## 'file': 'waeup_management_theme.zexp', |
---|
294 | ## }, |
---|
295 | ## ), |
---|
296 | ## } |
---|
297 | ## |
---|
298 | ## |
---|
299 | ## theme_ids = theme_container.objectIds() |
---|
300 | ## theme_container.manage_delObjects(theme_ids) |
---|
301 | ## target_themes = themes_list[Target] |
---|
302 | ## for theme in target_themes: |
---|
303 | ## pr(" Importing %s theme" % theme['id']) |
---|
304 | ## zexppath = os.path.join(zexpdir, theme['file']) |
---|
305 | ## try: |
---|
306 | ## theme_container._importObjectFromFile(zexppath) |
---|
307 | ## except: |
---|
308 | ## pr(" Could not import theme %s" % theme['id']) |
---|
309 | ## |
---|
310 | ## # set the first theme in the list as the default one. |
---|
311 | ## theme_container.setDefaultTheme(target_themes[0]['id']) |
---|
312 | ###) |
---|
313 | |
---|
314 | |
---|
315 | ########################################## |
---|
316 | # portal types |
---|
317 | ########################################## |
---|
318 | dtypes = portal.getWAeUPTypes() |
---|
319 | self.verifyFlexibleTypes(dtypes) |
---|
320 | self.allowContentTypes('University', ('Workspace','Section',)) |
---|
321 | ########################################## |
---|
322 | # Schemas |
---|
323 | ########################################## |
---|
324 | pr("Verifying %(product_name)s schemas" % vars()) |
---|
325 | self.verifySchemas(portal.getWAeUPSchemas()) |
---|
326 | ########################################## |
---|
327 | # widgets |
---|
328 | ########################################## |
---|
329 | pr("Verifying %(product_name)s widgets" % vars()) |
---|
330 | self.verifyWidgets(portal.getWAeUPWidgets()) |
---|
331 | ########################################## |
---|
332 | # layouts |
---|
333 | ########################################## |
---|
334 | pr("Verifying %(product_name)s layouts" % vars()) |
---|
335 | self.verifyLayouts(portal.getWAeUPLayouts()) |
---|
336 | ########################################## |
---|
337 | # Vocabularies |
---|
338 | ########################################## |
---|
339 | pr("Verifying %(product_name)s vocabularies" % vars()) |
---|
340 | self.verifyVocabularies(portal.getWAeUPVocabularies()) |
---|
341 | ########################################## |
---|
342 | # Groups |
---|
343 | ########################################## |
---|
344 | |
---|
345 | self.installCustomWorkflows() |
---|
346 | self.verifyWorkflowAssociation() |
---|
347 | |
---|
348 | pr("End of specific %(product_name)s install" % vars()) |
---|
349 | #return '\n'.join(log) |
---|
350 | self.finalize() |
---|
351 | |
---|
352 | |
---|
353 | def verifyPortlets(self, portlets=(), object=None): ###( |
---|
354 | """Verify the existence of given portet in the object's portlet |
---|
355 | container. If not found, a portlet is instantiated. |
---|
356 | Existing portlets are not affected. |
---|
357 | |
---|
358 | 'portlets' is a tuple with the dictionaries given by the export tab |
---|
359 | as entries. |
---|
360 | The default object is the portal itself. |
---|
361 | |
---|
362 | return the list a new portlet ids. |
---|
363 | """ |
---|
364 | |
---|
365 | if object is None: |
---|
366 | object = self.portal |
---|
367 | |
---|
368 | self.log('Verifying portlets on %s' % object.absolute_url(relative=1)) |
---|
369 | |
---|
370 | portlet_container = self.getPortletContainer(object, create=1) |
---|
371 | |
---|
372 | ttool = self.getTool('portal_types') |
---|
373 | |
---|
374 | returned = [] |
---|
375 | for new_portlet in portlets: |
---|
376 | existing_portlets = portlet_container.listPortlets() |
---|
377 | updated = 0 |
---|
378 | |
---|
379 | # Check if the portlet needs an update |
---|
380 | identifier = new_portlet.get('identifier') |
---|
381 | if identifier: |
---|
382 | for portlet in existing_portlets: |
---|
383 | if identifier == portlet.identifier: |
---|
384 | self.log(" Update of portlet: %s" % portlet) |
---|
385 | portlet.edit(**new_portlet) |
---|
386 | portlet_id = portlet.getId() |
---|
387 | updated = 1 |
---|
388 | continue |
---|
389 | slot = new_portlet.get('slot') |
---|
390 | if slot: |
---|
391 | for portlet in existing_portlets: |
---|
392 | if slot == portlet.slot: |
---|
393 | self.log(" Update of portlet: %s" % portlet) |
---|
394 | portlet.edit(**new_portlet) |
---|
395 | portlet_id = portlet.getId() |
---|
396 | updated = 1 |
---|
397 | continue |
---|
398 | |
---|
399 | if not updated: |
---|
400 | self.log(" Creation of portlet: %s" % new_portlet) |
---|
401 | portlet_id = self.portal.portal_cpsportlets.createPortlet( |
---|
402 | ptype_id=new_portlet['type'], |
---|
403 | context=object, |
---|
404 | **new_portlet) |
---|
405 | if portlet_id not in returned: |
---|
406 | returned.append(portlet_id) |
---|
407 | return returned |
---|
408 | ###) |
---|
409 | |
---|
410 | def installCustomWorkflows(self): ###( |
---|
411 | """Installs custom workflows |
---|
412 | """ |
---|
413 | from Products.WAeUP.Workflows.WAeUPWorkflow import \ |
---|
414 | waeupWorkflowsInstall |
---|
415 | |
---|
416 | waeupWorkflowsInstall(self.context) |
---|
417 | |
---|
418 | ###) |
---|
419 | |
---|
420 | def verifyWorkflowAssociation(self): ###( |
---|
421 | """Verify workflow association |
---|
422 | """ |
---|
423 | ws_chains = { |
---|
424 | 'Student': 'waeup_workspace_wf', |
---|
425 | 'Jamb': 'waeup_workspace_wf', |
---|
426 | } |
---|
427 | |
---|
428 | se_chains = { 'University': 'waeup_section_wf', |
---|
429 | 'AcademicsFolder': 'waeup_section_wf', |
---|
430 | 'StudentsFolder': 'waeup_student_wf', |
---|
431 | 'Student': 'waeup_student_wf', |
---|
432 | 'StudentPersonal': 'waeup_student_wf', |
---|
433 | 'StudentEligibility': 'waeup_student_wf', |
---|
434 | 'StudentDocuments': 'waeup_student_wf', |
---|
435 | 'Jamb': 'waeup_section_wf', |
---|
436 | 'ScratchCard': 'waeup_section_wf', |
---|
437 | 'Faculty': 'waeup_section_wf', |
---|
438 | 'Department': 'waeup_section_wf', |
---|
439 | 'Course': 'waeup_section_wf', |
---|
440 | 'StudyLevel': 'waeup_student_wf', |
---|
441 | 'Semester': 'waeup_student_wf', |
---|
442 | 'CourseTicket': 'waeup_student_wf', |
---|
443 | 'AccoFolder': 'waeup_section_wf', |
---|
444 | 'Accommodation': 'waeup_section_wf', |
---|
445 | } |
---|
446 | |
---|
447 | self.verifyLocalWorkflowChains(self.portal['workspaces'], |
---|
448 | ws_chains, |
---|
449 | destructive=1) |
---|
450 | self.verifyLocalWorkflowChains(self.portal['sections'], |
---|
451 | se_chains, |
---|
452 | destructive=1) |
---|
453 | ###) |
---|
454 | |
---|
455 | def verifyFaculties(self, academics): ###( |
---|
456 | """install Universityspecific Faculies with Departments""" |
---|
457 | faculties = [ |
---|
458 | ## {'id': 'agri', ###( |
---|
459 | ## 'Title': 'Agriculture', |
---|
460 | ## 'departments': [ |
---|
461 | ## { 'id': 'dep1', ###( |
---|
462 | ## 'Title': 'One', |
---|
463 | ## }, |
---|
464 | ## ], |
---|
465 | ## },###) |
---|
466 | { 'id': 'science', |
---|
467 | 'Title': 'Science', |
---|
468 | 'departments': [ |
---|
469 | { 'id': 'bio', ###( |
---|
470 | 'Title': 'Biochemistry', |
---|
471 | }, |
---|
472 | { 'id': 'bot', |
---|
473 | 'Title': 'Botany', |
---|
474 | }, |
---|
475 | { 'id': 'che', |
---|
476 | 'Title': 'Chemistry', |
---|
477 | }, |
---|
478 | { 'id': 'com', |
---|
479 | 'Title': 'Computer Science', |
---|
480 | }, |
---|
481 | { 'id': 'geo', |
---|
482 | 'Title': 'Geologie', |
---|
483 | }, |
---|
484 | { 'id': 'mat', |
---|
485 | 'Title': 'Mathematics', |
---|
486 | }, |
---|
487 | { 'id': 'mic', |
---|
488 | 'Title': 'Microbiology', |
---|
489 | }, |
---|
490 | { 'id': 'opt', |
---|
491 | 'Title': 'Optometry', |
---|
492 | }, |
---|
493 | { 'id': 'phy', |
---|
494 | 'Title': 'Physics', |
---|
495 | }, |
---|
496 | { 'id': 'zoo', |
---|
497 | 'Title': 'Zoology', |
---|
498 | }, |
---|
499 | ], |
---|
500 | },###) |
---|
501 | ]###) |
---|
502 | self.log('Verifying Faculties in %s' % academics.absolute_url(relative=1)) |
---|
503 | for faculty in faculties: |
---|
504 | fid = faculty['id'] |
---|
505 | f = getattr(academics,fid,None) |
---|
506 | self.log('Checking Faculty %(id)s = %(Title)s' % faculty) |
---|
507 | if f is None: |
---|
508 | self.log('Creating Faculty %(id)s = %(Title)s' % faculty) |
---|
509 | academics.invokeFactory('Faculty', fid) |
---|
510 | f = getattr(academics,fid) |
---|
511 | f.getContent().edit(mapping=faculty) |
---|
512 | for department in faculty['departments']: |
---|
513 | self.log('Checking Department %(id)s = %(Title)s' % department) |
---|
514 | did = department['id'] |
---|
515 | d = getattr(f,did,None) |
---|
516 | if d is None: |
---|
517 | self.log('Creating Department %(id)s = %(Title)s' % department) |
---|
518 | f.invokeFactory('Department', did) |
---|
519 | d = getattr(f,did) |
---|
520 | d.getContent().edit(mapping=department) |
---|
521 | ###) |
---|
522 | |
---|
523 | |
---|
524 | |
---|
525 | def install(self): ###( |
---|
526 | installer = WAeUPInstaller(self) |
---|
527 | installer.install(self) |
---|
528 | dirtool = getattr(self,'portal_directories') |
---|
529 | groups = dirtool.groups |
---|
530 | for delEntry in ('StudentManager',): |
---|
531 | if delEntry in groups.listEntryIds(): |
---|
532 | groups.deleteEntry(delEntry) |
---|
533 | for newEntry in ('Students',): |
---|
534 | if newEntry not in groups.listEntryIds(): |
---|
535 | groups.createEntry({'group': newEntry, |
---|
536 | 'members': []}) |
---|
537 | #groups.manage_setLocalGroupRoles(groupid = 'StudentManager',roles=('Manager',)) |
---|
538 | #groups.manage_setLocalGroupRoles(groupid = 'Students',roles=('Contributor',)) |
---|
539 | sections = getattr(self,'sections') |
---|
540 | waeup = getattr(sections,SRPP_ID,None) |
---|
541 | if not waeup: |
---|
542 | sections.invokeFactory('University',SRPP_ID) |
---|
543 | waeup = getattr(sections,SRPP_ID) |
---|
544 | waeup.getContent().edit(mapping={'Title':SRPP_TITLE}) |
---|
545 | waeup.folder_localrole_add(member_ids=('group:Students',), |
---|
546 | member_role='SectionReviewer', |
---|
547 | ) |
---|
548 | waeup.invokeFactory('StudentsFolder','students') |
---|
549 | students = getattr(waeup,'students').getContent() |
---|
550 | students.edit(mapping={'Title':'Students'}) |
---|
551 | waeup.folder_localrole_add(member_ids=('group:Students',), |
---|
552 | member_role='SectionReviewer', |
---|
553 | ) |
---|
554 | ## waeup.content_create(type_name='AcademicsFolder',title='academics') |
---|
555 | ## sections.waeup.folder_localrole_add(member_ids=('group:StudentManager',), |
---|
556 | ## member_role='SectionManager', |
---|
557 | ## ) |
---|
558 | waeup.students.manage_setLocalGroupRoles(groupid = 'Students',roles=('Contributor',)) |
---|
559 | waeup.invokeFactory('AcademicsFolder','academics', title='Academics') |
---|
560 | academics = getattr(waeup,'academics').getContent() |
---|
561 | academics.edit(mapping={'Title':'Academics'}) |
---|
562 | waeup.invokeFactory('AccoFolder','accommodation', title='Accommodation') |
---|
563 | accommodation = getattr(waeup,'accommodation').getContent() |
---|
564 | accommodation.edit(mapping={'Title':'Accommodation'}) |
---|
565 | academics = getattr(waeup,'academics',None) |
---|
566 | if academics is None: |
---|
567 | waeup.invokeFactory('AcademicsFolder','academics') |
---|
568 | academics = getattr(waeup,'academics') |
---|
569 | academics.getContent().edit(mapping={'Title':'Academics'}) |
---|
570 | installer.verifyFaculties(academics) |
---|
571 | if not hasattr(waeup,'accommodation'): |
---|
572 | waeup.invokeFactory('AccoFolder','accommodation') |
---|
573 | accommodation = getattr(waeup,'accommodation').getContent() |
---|
574 | accommodation.edit(mapping={'Title':'Accommodation'}) |
---|
575 | waeup.manage_setLocalGroupRoles(groupid = 'role:Anonymous',roles=('SectionReader',)) |
---|
576 | # portlets ###( |
---|
577 | # |
---|
578 | portlets = ( |
---|
579 | ## {'identifier': 'waeup_main_tabs', |
---|
580 | ## 'type': 'Custom Portlet', |
---|
581 | ## 'slot': 'main_tabs', |
---|
582 | ## 'order': 0, |
---|
583 | ## 'render_method': 'portlet_main_navigation', |
---|
584 | ## 'Title': 'main tabs', |
---|
585 | ## }, |
---|
586 | {#'identifier': 'waeup_breadcrumbs', |
---|
587 | 'type': 'Breadcrumbs Portlet', |
---|
588 | 'slot': 'waeup_breadcrumbs', |
---|
589 | 'first_item': 0, |
---|
590 | 'display_site_root': 0, |
---|
591 | 'Title': 'waeup_breadcrumbs', |
---|
592 | 'display': 'horizontal_trail', |
---|
593 | 'display_hidden_folders': 0, |
---|
594 | 'order': 0, |
---|
595 | }, |
---|
596 | {#'identifier': 'waeup_main_tab_actions', |
---|
597 | 'type': 'Actions Portlet', |
---|
598 | 'slot': 'main_tabs', |
---|
599 | 'order': 0, |
---|
600 | 'categories': ['main_tabs',], |
---|
601 | 'Title': 'waep_main_tab_actions', |
---|
602 | }, |
---|
603 | {#'identifier': 'waeup_object_actions', |
---|
604 | 'type': 'Actions Portlet', |
---|
605 | 'slot': 'waeup_object_actions', |
---|
606 | 'order': 0, |
---|
607 | 'categories': ['object',], |
---|
608 | 'Title': 'waep_manager_actions', |
---|
609 | }, |
---|
610 | {#'identifier': 'waeup_left_top', |
---|
611 | 'type': 'Custom Portlet', |
---|
612 | 'slot': 'left_top', |
---|
613 | 'order': 0, |
---|
614 | 'render_method': 'portlet_session_info', |
---|
615 | 'Title': 'Session Info', |
---|
616 | }, |
---|
617 | ) |
---|
618 | installer.verifyPortletContainer(waeup) |
---|
619 | installer.verifyPortlets(portlets,waeup) |
---|
620 | |
---|
621 | ###) |
---|
622 | return installer.logResult() |
---|
623 | ###) |
---|
624 | |
---|
625 | def migrate(self): ###( |
---|
626 | "update data" |
---|
627 | log = [] |
---|
628 | prlog = log.append |
---|
629 | |
---|
630 | def pr(msg, prlog=prlog): |
---|
631 | prlog('%s' % msg) |
---|
632 | |
---|
633 | sections = getattr(self,'sections') |
---|
634 | waeup = getattr(sections,SRPP_ID,None) |
---|
635 | pr( "Start migrate") |
---|
636 | pr("migrating Students") |
---|
637 | students = getattr(waeup,'students') |
---|
638 | pr("migrating courses") |
---|
639 | academics = getattr(waeup,'academics') |
---|
640 | for fac in [getattr(academics,f.id) for f in academics.contentValues(filter={'portal_type': ('Faculty',)})]: |
---|
641 | pr("Faculty: %s" % fac.title_or_id()) |
---|
642 | for dep in [getattr(fac,d.id) for d in fac.contentValues(filter={'portal_type': ('Department',)})]: |
---|
643 | pr("Department: %s" % dep.title_or_id()) |
---|
644 | for course in [getattr(dep,c.id) for c in dep.contentValues(filter={'portal_type': ('Course',)})]: |
---|
645 | pr("Course: %s" % course.title_or_id()) |
---|
646 | content = course.getContent() |
---|
647 | heading = getattr(content,'heading',course.id) |
---|
648 | pr("heading = %(heading)s" % vars()) |
---|
649 | content.edit(mapping={'Title': heading}) |
---|
650 | pr("migrating halls") |
---|
651 | for ac in [getattr(waeup,a.id) for a in waeup.contentValues(filter={'portal_type': ('AccoFolder',)})]: |
---|
652 | for hall in [getattr(ac,h.id) for h in ac.contentValues(filter={'portal_type': ('Accommodation',)})]: |
---|
653 | pr("Hall: %s" % hall.title_or_id()) |
---|
654 | content = hall.getContent() |
---|
655 | heading = getattr(content,'heading',hall.id) |
---|
656 | pr("heading = %(heading)s" % vars()) |
---|
657 | content.edit(mapping={'Title': heading}) |
---|
658 | return '\n'.join(log) |
---|
659 | |
---|
660 | ###) |
---|
661 | |
---|