Index: waeup_product/trunk/Extensions/install.py
===================================================================
--- waeup_product/trunk/Extensions/install.py	(revision 138)
+++ waeup_product/trunk/Extensions/install.py	(revision 139)
@@ -1,6 +1,7 @@
 #-*- mode: python; mode: fold -*-
 # $Id$
+from Products.ExternalMethod.ExternalMethod import ExternalMethod
 from Products.CPSInstaller.CPSInstaller import CPSInstaller
-from Products.CMFCore.CMFCorePermissions import View, ModifyPortalContent
+from Products.CMFCore.CMFCorePermissions import View, ModifyPortalContent,AccessContentsInformation
 from Products.WAeUP.WAeUPPermissions import UniversityManage, StudentManage,FacultyManage,\
                                             DepartmentManage,CourseManage
@@ -18,4 +19,7 @@
 from Products.WAeUP.Students import addStudentsFolder
 
+SRPP_ID = "demouni"
+SRPP_TITLE = "Demo University"
+
 class WAeUPInstaller(CPSInstaller):
     """
@@ -26,7 +30,12 @@
     def install(self,portal):
         "install"
+        log = []
+        prlog = log.append
+        
+        def pr(msg, prlog=prlog):
+            prlog('%s<br>' % msg)
 
         product_name = self.product_name
-        self.log("Starting %(product_name)s install" % vars() )
+        pr("Starting %(product_name)s install" % vars() )
 
         # Roles and Permissions ###(
@@ -64,6 +73,35 @@
         }
         self.setupPortalPermissions(waeup_perms)
-
-###)
+        ###)
+
+        # external methods ###(
+        #
+        ext_methods = ( { 'id': 'waeup_migrate',
+                          'title': 'WAeUP (migrate from an earlier version)',
+                          'script': 'WAeUP.install',
+                          'method': 'migrate',
+                          'protected': 1,
+                        },
+                      )
+        portal_objectIds = portal.objectIds()
+        for meth in ext_methods:
+            method = meth['id']
+            if method in portal_objectIds:
+                portal._delObject(method)
+            pr('Creating %s External Method' % method)
+            ext_method = ExternalMethod(method,
+                                        meth['title'],
+                                        meth['script'],
+                                        meth['method'])
+            portal._setObject(method, ext_method)
+            if method in portal_objectIds:
+                manage_perms = portal[method].manage_permission
+                if meth['protected']:
+                    pr("Protecting %s" % method)
+                    manage_perms(View, roles=['Manager'], acquire=0)
+                    manage_perms(AccessContentsInformation, roles=['Manager'], acquire=0)
+                else:
+                    manage_perms(View, roles=['Manager'], acquire=1)
+        ###)
 
         ##########################################
@@ -142,8 +180,10 @@
         # main_tab actions ###(
         ##########################################
+        path = "/sections/%(SRPP_ID)s" % globals()  
         actions = ( { 'tool'      : 'portal_actions',
                         'id'        : 'student_administration',
                         'name'      : 'Students',
-                        'action'    : 'string:$folder_url/students',
+                        #'action'    : 'string:$folder_url/students',
+                        'action'    : 'string:$portal_url%(path)s/students' % vars(),
                         'permission': (View, ),
                         'category'  : 'main_tabs',
@@ -153,6 +193,7 @@
                         'id'        : 'Academics',
                         'name'      : 'Academics',
-                        #'action'    : 'string:${portal_url}/sections/waeup/academics/academics_view',
-                        'action'    : 'string:$folder_url/academics',
+                        'action'    : 'string:$portal_url%(path)s/academics' % vars(),
+                        #'action'    : 'string:${portal_url}/sections/unidemo',
+                        #'action'    : 'string:$folder_url/academics',
                         'permission': (View ),
                         'category'  : 'main_tabs',
@@ -162,6 +203,6 @@
                         'id'        : 'accomodation',
                         'name'      : 'Accommodation',
+                        'action'    : 'string:$portal_url%(path)s/accommodation' % vars(),
                         #'action'    : 'string:${portal_url}/sections/waeup/accommodation/accommodation_index_html',
-                        'action'    : 'string:$folder_url/accommodation',
                         'permissions': (View),
                         #'permissions': (ModifyPortalContent,UniversityManage,StudentManage),
@@ -230,5 +271,5 @@
         # skins
         ##########################################
-        self.log("Verifying %(product_name)s skinss" % vars())
+        pr("Verifying %(product_name)s skinss" % vars())
         wskins = { 'waeup_default' : 'Products/WAeUP/skins/waeup_default',
                    'waeup_faculty' : 'Products/WAeUP/skins/waeup_faculty',
@@ -238,4 +279,35 @@
         self.resetSkinCache()
 
+        # Themes ###(
+        #
+        # Importing portal themes
+##        theme_container = getattr(portal, 'portal_themes')
+##            # the first theme in each category is the default theme.
+##        themes_list = {'WAeUP':    ({'id': 'waeup_plain_theme',
+##                                  'file': 'waeup_plain_theme.zexp',
+##                                  },
+##                                  {'id': 'waeup_management_theme',
+##                                   'file': 'waeup_management_theme.zexp',
+##                                  },
+##                                 ),
+##                      }
+##    
+##
+##        theme_ids = theme_container.objectIds()
+##        theme_container.manage_delObjects(theme_ids)
+##        target_themes = themes_list[Target]
+##        for theme in target_themes:
+##            pr(" Importing %s theme" % theme['id'])
+##            zexppath = os.path.join(zexpdir, theme['file'])
+##            try:
+##                theme_container._importObjectFromFile(zexppath)
+##            except:
+##                pr("    Could not import theme  %s" % theme['id'])
+##
+##        # set the first theme in the list as the default one.
+##        theme_container.setDefaultTheme(target_themes[0]['id'])
+###)
+    
+        
         ##########################################
         # portal types
@@ -247,20 +319,20 @@
         # Schemas
         ##########################################
-        self.log("Verifying %(product_name)s schemas" % vars())
+        pr("Verifying %(product_name)s schemas" % vars())
         self.verifySchemas(portal.getWAeUPSchemas())
         ##########################################
         # widgets
         ##########################################
-        self.log("Verifying %(product_name)s widgets" % vars())
+        pr("Verifying %(product_name)s widgets" % vars())
         self.verifyWidgets(portal.getWAeUPWidgets())
         ##########################################
         # layouts
         ##########################################
-        self.log("Verifying %(product_name)s layouts" % vars())
+        pr("Verifying %(product_name)s layouts" % vars())
         self.verifyLayouts(portal.getWAeUPLayouts())
         ##########################################
         # Vocabularies
         ##########################################
-        self.log("Verifying %(product_name)s vocabularies" % vars())
+        pr("Verifying %(product_name)s vocabularies" % vars())
         self.verifyVocabularies(portal.getWAeUPVocabularies())
         ##########################################
@@ -271,5 +343,6 @@
         self.verifyWorkflowAssociation()
 
-        self.log("End of specific %(product_name)s install" % vars())
+        pr("End of specific %(product_name)s install" % vars())
+        #return '\n'.join(log)
         self.finalize()
 
@@ -329,22 +402,38 @@
     #groups.manage_setLocalGroupRoles(groupid = 'Students',roles=('Contributor',))
     sections = getattr(self,'sections')
-    waeup = getattr(sections,'waeup',None)
+    waeup = getattr(sections,SRPP_ID,None)
     if not waeup:
-        sections.content_create(type_name='University',title='waeup')
-        sections.waeup.folder_localrole_add(member_ids=('group:Students',),
+        sections.invokeFactory('University',SRPP_ID)
+        waeup = getattr(sections,SRPP_ID)
+        waeup.getContent().edit(mapping={'Title':SRPP_TITLE})
+        waeup.folder_localrole_add(member_ids=('group:Students',),
                                             member_role='SectionReviewer',
                                             )
-        sections.waeup.content_create(type_name='StudentsFolder',title='students')
-        sections.waeup.folder_localrole_add(member_ids=('group:Students',),
+        waeup.invokeFactory('StudentsFolder','students')
+        students = getattr(waeup,'students').getContent()
+        students.edit(mapping={'Title':'Students'})
+        waeup.folder_localrole_add(member_ids=('group:Students',),
                                             member_role='SectionReviewer',
                                             )
-        sections.waeup.content_create(type_name='AcademicsFolder',title='academics')
+##        waeup.content_create(type_name='AcademicsFolder',title='academics')
 ##        sections.waeup.folder_localrole_add(member_ids=('group:StudentManager',),
 ##                                            member_role='SectionManager',
 ##                                            )
-        sections.waeup.students.manage_setLocalGroupRoles(groupid = 'Students',roles=('Contributor',))
-    elif not hasattr(waeup,'academics'):
-        waeup.content_create(type_name='AcademicsFolder',title='academics')
-    sections.waeup.manage_setLocalGroupRoles(groupid = 'role:Anonymous',roles=('SectionReader',))
+        waeup.students.manage_setLocalGroupRoles(groupid = 'Students',roles=('Contributor',))
+        waeup.invokeFactory('AcademicsFolder','academics', title='Academics')
+        academics = getattr(waeup,'academics').getContent()
+        academics.edit(mapping={'Title':'Academics'})
+        waeup.invokeFactory('AccoFolder','accommodation', title='Accommodation')
+        accommodation = getattr(waeup,'accommodation').getContent()
+        accommodation.edit(mapping={'Title':'Accommodation'})
+    if not hasattr(waeup,'academics'):
+        waeup.invokeFactory('AcademicsFolder','academics')
+        academics = getattr(waeup,'academics').getContent()
+        academics.edit(mapping={'Title':'Academics'})
+    if not hasattr(waeup,'accommodation'):
+        waeup.invokeFactory('AccoFolder','accommodation')
+        accommodation = getattr(waeup,'accommodation').getContent()
+        accommodation.edit(mapping={'Title':'Accommodation'})
+    waeup.manage_setLocalGroupRoles(groupid = 'role:Anonymous',roles=('SectionReader',))
     # portlets ###(
     #
@@ -395,2 +484,35 @@
 
     return installer.logResult()
+
+def migrate(self):
+    "update data"
+    log = []
+    prlog = log.append
+
+    def pr(msg, prlog=prlog):
+        prlog('%s<br>' % msg)
+
+    sections = getattr(self,'sections')
+    waeup = getattr(sections,'waeup',None)
+    pr( "Start migrate")
+    pr("migrating courses")
+    for fac in [getattr(waeup,f.id) for f in waeup.contentValues(filter={'portal_type': ('Faculty',)})]:
+        pr("Faculty: %s" % fac.title_or_id())
+        for dep in [getattr(fac,d.id) for d in fac.contentValues(filter={'portal_type': ('Department',)})]:
+            pr("Department: %s" % dep.title_or_id())
+            for course in [getattr(dep,c.id) for c in dep.contentValues(filter={'portal_type': ('Course',)})]:
+                pr("Course: %s" % course.title_or_id())
+                content = course.getContent()
+                heading = getattr(content,'heading',course.id)
+                pr("heading = %(heading)s" % vars())
+                content.edit(mapping={'Title': heading})
+    pr("migrating halls")
+    for ac in [getattr(waeup,a.id) for a in waeup.contentValues(filter={'portal_type': ('AccoFolder',)})]:
+        for hall in [getattr(ac,h.id) for h in ac.contentValues(filter={'portal_type': ('Accommodation',)})]:
+            pr("Hall: %s" % hall.title_or_id())
+            content = hall.getContent()
+            heading = getattr(content,'heading',hall.id)
+            pr("heading = %(heading)s" % vars())
+            content.edit(mapping={'Title': heading})
+    return '\n'.join(log)
+                
