| 1 | #-*- mode: python; mode: fold -*- |
|---|
| 2 | # $Id: install.py 195 2005-11-22 18:23:15Z 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 | |
|---|
| 363 | def verifyPortlets(self, portlets=(), object=None): ###( |
|---|
| 364 | """Verify the existence of given portet in the object's portlet |
|---|
| 365 | container. If not found, a portlet is instantiated. |
|---|
| 366 | Existing portlets are not affected. |
|---|
| 367 | |
|---|
| 368 | 'portlets' is a tuple with the dictionaries given by the export tab |
|---|
| 369 | as entries. |
|---|
| 370 | The default object is the portal itself. |
|---|
| 371 | |
|---|
| 372 | return the list a new portlet ids. |
|---|
| 373 | """ |
|---|
| 374 | |
|---|
| 375 | if object is None: |
|---|
| 376 | object = self.portal |
|---|
| 377 | |
|---|
| 378 | self.log('Verifying portlets on %s' % object.absolute_url(relative=1)) |
|---|
| 379 | |
|---|
| 380 | portlet_container = self.getPortletContainer(object, create=1) |
|---|
| 381 | |
|---|
| 382 | ttool = self.getTool('portal_types') |
|---|
| 383 | |
|---|
| 384 | returned = [] |
|---|
| 385 | for new_portlet in portlets: |
|---|
| 386 | existing_portlets = portlet_container.listPortlets() |
|---|
| 387 | updated = 0 |
|---|
| 388 | |
|---|
| 389 | # Check if the portlet needs an update |
|---|
| 390 | identifier = new_portlet.get('identifier') |
|---|
| 391 | if identifier: |
|---|
| 392 | for portlet in existing_portlets: |
|---|
| 393 | if identifier == portlet.identifier: |
|---|
| 394 | self.log(" Update of portlet: %s" % portlet) |
|---|
| 395 | portlet.edit(**new_portlet) |
|---|
| 396 | portlet_id = portlet.getId() |
|---|
| 397 | updated = 1 |
|---|
| 398 | continue |
|---|
| 399 | slot = new_portlet.get('slot') |
|---|
| 400 | if slot: |
|---|
| 401 | for portlet in existing_portlets: |
|---|
| 402 | if slot == portlet.slot: |
|---|
| 403 | self.log(" Update of portlet: %s" % portlet) |
|---|
| 404 | portlet.edit(**new_portlet) |
|---|
| 405 | portlet_id = portlet.getId() |
|---|
| 406 | updated = 1 |
|---|
| 407 | continue |
|---|
| 408 | |
|---|
| 409 | if not updated: |
|---|
| 410 | self.log(" Creation of portlet: %s" % new_portlet) |
|---|
| 411 | portlet_id = self.portal.portal_cpsportlets.createPortlet( |
|---|
| 412 | ptype_id=new_portlet['type'], |
|---|
| 413 | context=object, |
|---|
| 414 | **new_portlet) |
|---|
| 415 | if portlet_id not in returned: |
|---|
| 416 | returned.append(portlet_id) |
|---|
| 417 | return returned |
|---|
| 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 | groups = dirtool.groups |
|---|
| 540 | for delEntry in ('StudentManager',): |
|---|
| 541 | if delEntry in groups.listEntryIds(): |
|---|
| 542 | groups.deleteEntry(delEntry) |
|---|
| 543 | for newEntry in ('Students',): |
|---|
| 544 | if newEntry not in groups.listEntryIds(): |
|---|
| 545 | groups.createEntry({'group': newEntry, |
|---|
| 546 | 'members': []}) |
|---|
| 547 | #groups.manage_setLocalGroupRoles(groupid = 'StudentManager',roles=('Manager',)) |
|---|
| 548 | #groups.manage_setLocalGroupRoles(groupid = 'Students',roles=('Contributor',)) |
|---|
| 549 | sections = getattr(self,'sections') |
|---|
| 550 | waeup = getattr(sections,SRPP_ID,None) |
|---|
| 551 | if not waeup: |
|---|
| 552 | sections.invokeFactory('University',SRPP_ID) |
|---|
| 553 | waeup = getattr(sections,SRPP_ID) |
|---|
| 554 | waeup.getContent().edit(mapping={'Title':SRPP_TITLE}) |
|---|
| 555 | waeup.folder_localrole_add(member_ids=('group:Students',), |
|---|
| 556 | member_role='SectionReviewer', |
|---|
| 557 | ) |
|---|
| 558 | waeup.invokeFactory('StudentsFolder','students') |
|---|
| 559 | students = getattr(waeup,'students').getContent() |
|---|
| 560 | students.edit(mapping={'Title':'Students'}) |
|---|
| 561 | waeup.folder_localrole_add(member_ids=('group:Students',), |
|---|
| 562 | member_role='SectionReviewer', |
|---|
| 563 | ) |
|---|
| 564 | ## waeup.content_create(type_name='AcademicsFolder',title='academics') |
|---|
| 565 | ## sections.waeup.folder_localrole_add(member_ids=('group:StudentManager',), |
|---|
| 566 | ## member_role='SectionManager', |
|---|
| 567 | ## ) |
|---|
| 568 | waeup.students.manage_setLocalGroupRoles(groupid = 'Students',roles=('Contributor',)) |
|---|
| 569 | waeup.invokeFactory('AcademicsFolder','academics', title='Academics') |
|---|
| 570 | academics = getattr(waeup,'academics').getContent() |
|---|
| 571 | academics.edit(mapping={'Title':'Academics'}) |
|---|
| 572 | waeup.invokeFactory('AccoFolder','accommodation', title='Accommodation') |
|---|
| 573 | accommodation = getattr(waeup,'accommodation').getContent() |
|---|
| 574 | accommodation.edit(mapping={'Title':'Accommodation'}) |
|---|
| 575 | academics = getattr(waeup,'academics',None) |
|---|
| 576 | if academics is None: |
|---|
| 577 | waeup.invokeFactory('AcademicsFolder','academics') |
|---|
| 578 | academics = getattr(waeup,'academics') |
|---|
| 579 | academics.getContent().edit(mapping={'Title':'Academics'}) |
|---|
| 580 | installer.verifyFaculties(academics) |
|---|
| 581 | if not hasattr(waeup,'accommodation'): |
|---|
| 582 | waeup.invokeFactory('AccoFolder','accommodation') |
|---|
| 583 | accommodation = getattr(waeup,'accommodation').getContent() |
|---|
| 584 | accommodation.edit(mapping={'Title':'Accommodation'}) |
|---|
| 585 | waeup.manage_setLocalGroupRoles(groupid = 'role:Anonymous',roles=('SectionReader',)) |
|---|
| 586 | # portlets ###( |
|---|
| 587 | # |
|---|
| 588 | portlets = ( |
|---|
| 589 | ## {'identifier': 'waeup_main_tabs', |
|---|
| 590 | ## 'type': 'Custom Portlet', |
|---|
| 591 | ## 'slot': 'main_tabs', |
|---|
| 592 | ## 'order': 0, |
|---|
| 593 | ## 'render_method': 'portlet_main_navigation', |
|---|
| 594 | ## 'Title': 'main tabs', |
|---|
| 595 | ## }, |
|---|
| 596 | {#'identifier': 'waeup_breadcrumbs', |
|---|
| 597 | 'type': 'Breadcrumbs Portlet', |
|---|
| 598 | 'slot': 'waeup_breadcrumbs', |
|---|
| 599 | 'first_item': 0, |
|---|
| 600 | 'display_site_root': 0, |
|---|
| 601 | 'Title': 'waeup_breadcrumbs', |
|---|
| 602 | 'display': 'horizontal_trail', |
|---|
| 603 | 'display_hidden_folders': 0, |
|---|
| 604 | 'order': 0, |
|---|
| 605 | }, |
|---|
| 606 | {#'identifier': 'waeup_main_tab_actions', |
|---|
| 607 | 'type': 'Actions Portlet', |
|---|
| 608 | 'slot': 'main_tabs', |
|---|
| 609 | 'order': 0, |
|---|
| 610 | 'categories': ['main_tabs',], |
|---|
| 611 | 'Title': 'waep_main_tab_actions', |
|---|
| 612 | }, |
|---|
| 613 | {#'identifier': 'waeup_object_actions', |
|---|
| 614 | 'type': 'Actions Portlet', |
|---|
| 615 | 'slot': 'waeup_object_actions', |
|---|
| 616 | 'order': 0, |
|---|
| 617 | 'categories': ['object',], |
|---|
| 618 | 'Title': 'waep_manager_actions', |
|---|
| 619 | }, |
|---|
| 620 | {#'identifier': 'waeup_left_top', |
|---|
| 621 | 'type': 'Custom Portlet', |
|---|
| 622 | 'slot': 'left_top', |
|---|
| 623 | 'order': 0, |
|---|
| 624 | 'render_method': 'portlet_session_info', |
|---|
| 625 | 'Title': 'Session Info', |
|---|
| 626 | }, |
|---|
| 627 | ) |
|---|
| 628 | installer.verifyPortletContainer(waeup) |
|---|
| 629 | installer.verifyPortlets(portlets,waeup) |
|---|
| 630 | |
|---|
| 631 | ###) |
|---|
| 632 | return installer.logResult() |
|---|
| 633 | ###) |
|---|
| 634 | |
|---|
| 635 | def migrate(self): ###( |
|---|
| 636 | "update data" |
|---|
| 637 | log = [] |
|---|
| 638 | prlog = log.append |
|---|
| 639 | |
|---|
| 640 | def pr(msg, prlog=prlog): |
|---|
| 641 | prlog('%s' % msg) |
|---|
| 642 | |
|---|
| 643 | sections = getattr(self,'sections') |
|---|
| 644 | waeup = getattr(sections,SRPP_ID,None) |
|---|
| 645 | pr( "Start migrate") |
|---|
| 646 | pr("migrating Students") |
|---|
| 647 | students = getattr(waeup,'students') |
|---|
| 648 | pr("migrating courses") |
|---|
| 649 | academics = getattr(waeup,'academics') |
|---|
| 650 | for fac in [getattr(academics,f.id) for f in academics.contentValues(filter={'portal_type': ('Faculty',)})]: |
|---|
| 651 | pr("Faculty: %s" % fac.title_or_id()) |
|---|
| 652 | for dep in [getattr(fac,d.id) for d in fac.contentValues(filter={'portal_type': ('Department',)})]: |
|---|
| 653 | pr("Department: %s" % dep.title_or_id()) |
|---|
| 654 | for course in [getattr(dep,c.id) for c in dep.contentValues(filter={'portal_type': ('Course',)})]: |
|---|
| 655 | pr("Course: %s" % course.title_or_id()) |
|---|
| 656 | content = course.getContent() |
|---|
| 657 | heading = getattr(content,'heading',course.id) |
|---|
| 658 | pr("heading = %(heading)s" % vars()) |
|---|
| 659 | content.edit(mapping={'Title': heading}) |
|---|
| 660 | pr("migrating halls") |
|---|
| 661 | for ac in [getattr(waeup,a.id) for a in waeup.contentValues(filter={'portal_type': ('AccoFolder',)})]: |
|---|
| 662 | for hall in [getattr(ac,h.id) for h in ac.contentValues(filter={'portal_type': ('Accommodation',)})]: |
|---|
| 663 | pr("Hall: %s" % hall.title_or_id()) |
|---|
| 664 | content = hall.getContent() |
|---|
| 665 | heading = getattr(content,'heading',hall.id) |
|---|
| 666 | pr("heading = %(heading)s" % vars()) |
|---|
| 667 | content.edit(mapping={'Title': heading}) |
|---|
| 668 | return '\n'.join(log) |
|---|
| 669 | |
|---|
| 670 | ###) |
|---|
| 671 | |
|---|