Changeset 592


Ignore:
Timestamp:
29 Sep 2006, 12:45:10 (18 years ago)
Author:
joachim
Message:

export/import of localroles for faculties and departments.
howto use:
append to the export link &localroles = 1
http://z29.aixtraware.de/srp/campus/academics/exportDepartmentsToCSV&localroles=1
dito for the import link
http://z29.aixtraware.de/srp/campus/academics/loadDepartmentsFromCSV&localroles

1

befor importing:
copy the exportfile DepartmentLocalRoles_date.csv to DepartmentLocalRoles?.csv

File:
1 edited

Legend:

Unmodified
Added
Removed
  • WAeUP_SRP/trunk/Academics.py

    r583 r592  
    4747        return "Academic Section"
    4848
     49    def importLocalRoles(self,portal_type): ###(
     50        name = '%sLocalRoles' % portal_type
     51        logger = logging.getLogger('%s_import' % name)
     52        current = DateTime.DateTime().strftime("%d-%m-%y_%H_%M_%S")
     53        logger.info('Start exporting %(name)s to %(name)s_%(current)s.csv' % vars())
     54        export = []
     55        export.append('"code","users"')
     56        pm = self.portal_membership
     57        #import pdb;pdb.set_trace()
     58        try:
     59            imp_roles = csv.DictReader(open("%s/import/%s.csv" % (i_home,name),"rb"))
     60        except:
     61            logger.error('Error reading %s.csv' % name)
     62            return
     63        odict = {}
     64        for f in self.portal_catalog({'meta_type': portal_type}):
     65            odict[f.getId] = f.getObject()
     66        for role in imp_roles:
     67            obj_id = role['code']
     68            if obj_id in odict.keys():
     69                roles_dict = eval(role['users'])
     70                for r in roles_dict.keys():
     71                    if r.startswith('user'):
     72                        member_id = r.split(':')[1]
     73                        odict[obj_id].manage_setLocalRoles(member_id, roles_dict[r])
     74                        logger.info('importing role for %s %s %s' % (obj_id, member_id,roles_dict[r]))
     75
     76###)
     77
    4978    security.declareProtected(ModifyPortalContent,"loadFacultiesFromCSV")###(
    5079    def loadFacultiesFromCSV(self):
    5180        """install Universityspecific Faculies from CSV values"""
    5281        #return
     82        if self.REQUEST.get('localroles'):
     83            self.importLocalRoles('Faculty')
     84            return self.REQUEST.RESPONSE.redirect("%s" % self.REQUEST.get('URL1'))
    5385        name = 'Faculties'
    5486        no_import = False
     
    95127        """install Universityspecific Faculies from CSV values"""
    96128        #return
     129        if self.REQUEST.get('localroles'):
     130            self.importLocalRoles('Department')
     131            return self.REQUEST.RESPONSE.redirect("%s" % self.REQUEST.get('URL1'))
    97132        name = 'Departments'
    98133        no_import = False
     
    755790    ###)
    756791
     792    def exportLocalRoles(self,portal_type): ###(
     793        name = 'FacultiesLocalRoles'
     794        logger = logging.getLogger('%s_export' % name)
     795        current = DateTime.DateTime().strftime("%d-%m-%y_%H_%M_%S")
     796        logger.info('Start exporting %(name)s to %(name)s_%(current)s.csv' % vars())
     797        objects = [f.getObject() for f in self.portal_catalog({'meta_type': 'Faculty'})]
     798        export = []
     799        export.append('"code","users"')
     800        pm = self.portal_membership
     801        import pdb;pdb.set_trace()
     802        for obj in objects:
     803            lr = pm.getMergedLocalRoles(obj)
     804            logger.info('exporting %s %s ' % (obj.id, lr))
     805            export.append('"%s","%s"' % (obj.getId(),lr))
     806        open("%s/import/%s-%s.csv" % (i_home,name,current),"w+").write('\n'.join(export))
     807       
     808###)
     809       
    757810    security.declareProtected(ModifyPortalContent,"exportFacultiesToCSV")###(
    758811    def exportFacultiesToCSV(self):
    759812        """export Faculies to CSV"""
    760813        #return
     814        if self.REQUEST.get('localroles'):
     815            self.exportLocalRoles('Faculty')
     816            return self.REQUEST.RESPONSE.redirect("%s" % self.REQUEST.get('URL1'))
    761817        name = 'Faculties'
    762818        no_import = False
     
    789845        """export Faculies to CSV"""
    790846        #return
    791         import copy
     847        if self.REQUEST.get('localroles'):
     848            self.exportLocalRoles('Department')
     849            return self.REQUEST.RESPONSE.redirect("%s" % self.REQUEST.get('URL1'))
    792850        name = 'Departments'
    793851        no_import = False
Note: See TracChangeset for help on using the changeset viewer.