source: WAeUP_SRP/trunk/exportimport.py @ 5577

Last change on this file since 5577 was 4302, checked in by Henrik Bettermann, 15 years ago

store ids when removing students and check for removed ids when csdding new students

WAeUPTable alraedy contains methods for position ind course calculation

  • Property svn:keywords set to Id
File size: 9.1 KB
RevLine 
[200]1#-*- mode: python; mode: fold -*-
[486]2# $Id: exportimport.py 4302 2009-06-17 13:53:22Z henrik $
[199]3"""WAeUP Tool XML Adapter.
4
5An XML adapter tells the GenericSetup machinery howto im- / export persistent
6configuration that is relative to a specific CMF component such as our WAeUP
7Tool.
8
9GenericSetup uses the Zope3 interfaces and components machinery to find the
10right XML adapter for the right object. This is why we flagged our waeup tool
11with the `implements(IWAeUPTool)` class attribute and made an adapter
12association in the `configure.zcml` file.
13"""
[238]14import csv,re
[199]15
16# Zope3 component architecture
[502]17from zope.app import zapi
[199]18from zope.component import adapts
19from zope.interface import implements
20
21# Standard GenericSetup base classes and functions
22from Products.GenericSetup.utils import exportObjects
23from Products.GenericSetup.utils import importObjects
24from Products.GenericSetup.utils import XMLAdapterBase
25from Products.GenericSetup.utils import PropertyManagerHelpers
26
27from Products.CMFCore.utils import getToolByName
28
29# GenericSetup multi adapts a class that implement IWAeUP and a particular
30# ISetupEnvironment to and IBody (piece of XML configuration).
31from Products.GenericSetup.interfaces import IBody
32from Products.GenericSetup.interfaces import ISetupEnviron
[274]33from Products.WAeUP_SRP.interfaces import IWAeUPTool
[238]34import Globals
35p_home = Globals.package_home(globals())
36i_home = Globals.INSTANCE_HOME
[199]37
38TOOL = 'portal_waeup'
39NAME = 'waeup'
40
[502]41def importWAeUPTable(obj, parent_path, context, name):
42    """ Import subobjects recursively.
43    """
44    importer = zapi.queryMultiAdapter((obj, context), IBody)
[950]45
[502]46    path = '%s%s' % (parent_path, obj.getId().replace(' ', '_'))
47    __traceback_info__ = path
48    if importer:
49        path = '%s%s' % (parent_path, name)
50        filename = '%s%s' % (path, importer.suffix)
51        body = context.readDataFile(filename)
52        if body is not None:
53            importer.filename = filename # for error reporting
54            importer.body = body
55
56    if getattr(obj, 'objectValues', False):
57        for sub in obj.objectValues():
58            importObjects(sub, path+'/', context)
59
[199]60def exportWAeUP(context):
61    """Export our WAeUP tool configuration
62    """
63    site = context.getSite()
[282]64    tool = getattr(context,"campus",None)
[199]65    if tool is None:
66        logger = context.getLogger(NAME)
67        logger.info("Nothing to export.")
68        return
69    exportObjects(tool, '', context)
70
71def importWAeUP(context):
72    """Import WAeUP tool configuration
73    """
74    site = context.getSite()
[350]75    pm = site.portal_membership
[940]76    campus = getattr(site.portal_url.getPortalObject(),'campus',None)
77    if campus is not None:
[949]78        academics = getattr(campus,'academics',None)
79        students = getattr(campus,'students',None)
[963]80        accommodation = getattr(campus,'accommodation',None)
[3299]81        uploads = getattr(campus,'uploads',None)
[1414]82        campus.manage_setLocalGroupRoles(groupid='CampusOfficers',
[1432]83                                         roles=('SectionOfficer',))
[949]84        if academics is not None:
[955]85            academics.manage_setLocalGroupRoles(groupid='role:Authenticated',
[926]86                                         roles=('SectionReader',))
[1414]87            academics.manage_setLocalGroupRoles(groupid='AcademicsOfficers',
[1432]88                                         roles=('SectionOfficer',))
[949]89        if students is not None:
[2304]90            students.manage_setLocalGroupRoles(groupid = 'StudentsReaders',
91                                              roles=('SectionReader',))
[962]92            students.manage_setLocalGroupRoles(groupid = 'ClearanceOfficers',
[955]93                                              roles=('SectionReader',))
[1515]94            students.manage_setLocalGroupRoles(groupid = 'CourseAdvisers',
[1625]95                                              roles=('SectionReader',))
[1221]96            students.manage_setLocalGroupRoles(groupid='MemberAdmins',
[1414]97                                         roles=('SectionOfficer',))
98            students.manage_setLocalGroupRoles(groupid='StudentsOfficers',
[1432]99                                         roles=('SectionOfficer',))
[962]100            students.manage_setLocalGroupRoles(groupid = 'role:Student',
101                                              roles=('SectionReader',))
[963]102        if accommodation is not None:
103            accommodation.manage_setLocalGroupRoles(groupid='role:Student',
[1221]104                                         roles=('SectionReader',))
[1414]105            accommodation.manage_setLocalGroupRoles(groupid='AccommodationOfficers',
[1432]106                                         roles=('SectionOfficer',))
[3299]107        if uploads is not None:
108            uploads.manage_setLocalGroupRoles(groupid='UploadOfficers',
[3277]109                                         roles=('SectionOfficer',))
[955]110    members = getattr(site.portal_directories,'members')
111    if members is not None:
[957]112        members.manage_setLocalGroupRoles(groupid='MemberAdmins',
[955]113                                         roles=('SectionOfficer',))
[1432]114    students = getattr(site.portal_directories,'students')
115    if students is not None:
116        students.manage_setLocalGroupRoles(groupid='MemberAdmins',
[1433]117                                         roles=('SectionOfficer',))
118    waeup_stacking_dir = getattr(site.portal_directories,'waeup_stacking_dir')
119    if waeup_stacking_dir is not None:
120        waeup_stacking_dir.manage_setLocalGroupRoles(groupid='MemberAdmins',
[1515]121                                         roles=('SectionOfficer',))
[956]122
[926]123##    pm.setLocalGroupRoles(campus.academics,['role:Authenticated',
124##                                           ],'SectionReader')
[502]125    importWAeUPTable(site.portal_accommodation, '', context,'accommodation')
[1146]126    importWAeUPTable(site.courses_catalog, '', context,'courses_catalog')
[3494]127    importWAeUPTable(site.certificates_catalog, '', context,'certificates_catalog')
[1146]128    importWAeUPTable(site.payments_catalog, '', context,'payments_catalog')
[1625]129    importWAeUPTable(site.online_payments_import, '', context,'online_payments_import')
[502]130    importWAeUPTable(site.portal_pins, '', context,'pins')
[966]131    importWAeUPTable(site.portal_pumeresults, '', context,'pumeresults')
[1151]132    importWAeUPTable(site.returning_import, '', context,'returning_import')
[1146]133    importWAeUPTable(site.results_import, '', context,'results_import')
[2086]134    importWAeUPTable(site.students_catalog, '', context,'students_catalog')
[2094]135    importWAeUPTable(site.applicants_catalog, '', context,'applicants_catalog')
[2086]136    importWAeUPTable(site.course_results, '', context,'course_results')
[2257]137    importWAeUPTable(site.portal_catalog, '', context,'portal_catalog')
[1935]138    importWAeUPTable(site.portal_catalog_real, '', context,'portal_catalog_real')
[4302]139    importWAeUPTable(site.removed_student_ids, '', context,'removed_student_ids')
[3299]140
[2651]141    site.students_catalog.manage_setLocalGroupRoles(groupid='CampusOfficers',
142                                         roles=('SectionOfficer',))
[3006]143    site.payments_catalog.manage_setLocalGroupRoles(groupid='CampusOfficers',
144                                         roles=('SectionOfficer',))
145    site.applicants_catalog.manage_setLocalGroupRoles(groupid='CampusOfficers',
[3299]146                                         roles=('SectionOfficer',))
[3006]147    site.course_results.manage_setLocalGroupRoles(groupid='CampusOfficers',
[3299]148                                         roles=('SectionOfficer',))
[2304]149
[2258]150    site.portal_catalog.id = 'portal_catalog'
151    site.portal_catalog_real.id = 'portal_catalog_real'
[950]152
[2304]153
[502]154from Products.CPSCore.exportimport.catalog import CatalogToolXMLAdapter
155#from Products.GenericSetup.ZCatalog.exportimport import ZCatalogXMLAdapter
[363]156
157from interfaces import IWAeUPTable
158
[502]159class WAeUPTableXMLAdapter(CatalogToolXMLAdapter):
160#class WAeUPTableXMLAdapter(ZCatalogXMLAdapter):
[363]161    __used_for__ = IWAeUPTable
162    _LOGGER_ID = 'waeup_table'
163
[502]164##    def _importNode(self, node):
165##        """Import the object from the DOM node.
166##        """
167##        if self.environ.shouldPurge():
168##            self._purgeProperties()
169##            self._purgeObjects()
170##            self._purgeIndexes()
171##            self._purgeColumns()
172##
173##        self._logger.info('Catalog imported.')
[199]174# This the XMLAdapter itself. It encodes the im- / export logic that is specific
175# to our tool. `im- / exportObjects` functions will find it thanks to the zope
176# components machinery and the associations made in the configure.zcml file.
177
[282]178##class WAeUPXMLAdapter(XMLAdapterBase, PropertyManagerHelpers):
179##    """XML importer and exporter for the WAeUP tool.
180##
181##    Hence this XMLAdapter is really simple. To get more complete examples of
182##    what XMLAdapters are meant to do, please have a look at the
183##    CPSSkins.exportimport.py or CPSDirectory.exportimport.py files, for
184##    instance.
185##    """
186##
187##    adapts(IWAeUPTool, ISetupEnviron)
188##    implements(IBody)
189##
190##    _LOGGER_ID = NAME
191##    name = NAME
192##
193##    def _exportNode(self):
194##        """Export the object as a DOM node.
195##        """
196##        node = self._getObjectNode('object')
197##        node.appendChild(self._extractProperties())
198##        self._logger.info("WAeUP tool exported.")
199##        return node
200##
201##    def _importNode(self, node):
202##        """Import the object from the DOM node.
203##        """
204##        if self.environ.shouldPurge():
205##            self._purgeProperties()
206##        self._initProperties(node)
207##        self._logger.info("WAeUP tool imported.")
208##
Note: See TracBrowser for help on using the repository browser.