source: WAeUP_SRP/trunk/exportimport.py @ 5603

Last change on this file since 5603 was 5591, checked in by Henrik Bettermann, 14 years ago

Add AccessCodeOfficers? group.

  • Property svn:keywords set to Id
File size: 9.3 KB
Line 
1#-*- mode: python; mode: fold -*-
2# $Id: exportimport.py 5591 2010-11-16 07:29:35Z henrik $
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"""
14import csv,re
15
16# Zope3 component architecture
17from zope.app import zapi
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
33from Products.WAeUP_SRP.interfaces import IWAeUPTool
34import Globals
35p_home = Globals.package_home(globals())
36i_home = Globals.INSTANCE_HOME
37
38TOOL = 'portal_waeup'
39NAME = 'waeup'
40
41def importWAeUPTable(obj, parent_path, context, name):
42    """ Import subobjects recursively.
43    """
44    importer = zapi.queryMultiAdapter((obj, context), IBody)
45
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
60def exportWAeUP(context):
61    """Export our WAeUP tool configuration
62    """
63    site = context.getSite()
64    tool = getattr(context,"campus",None)
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()
75    pm = site.portal_membership
76    campus = getattr(site.portal_url.getPortalObject(),'campus',None)
77    if campus is not None:
78        academics = getattr(campus,'academics',None)
79        students = getattr(campus,'students',None)
80        accommodation = getattr(campus,'accommodation',None)
81        uploads = getattr(campus,'uploads',None)
82        pins = getattr(campus,'pins',None)
83        campus.manage_setLocalGroupRoles(groupid='CampusOfficers',
84                                         roles=('SectionOfficer',))
85        if academics is not None:
86            academics.manage_setLocalGroupRoles(groupid='role:Authenticated',
87                                         roles=('SectionReader',))
88            academics.manage_setLocalGroupRoles(groupid='AcademicsOfficers',
89                                         roles=('SectionOfficer',))
90        if students is not None:
91            students.manage_setLocalGroupRoles(groupid = 'StudentsReaders',
92                                              roles=('SectionReader',))
93            students.manage_setLocalGroupRoles(groupid = 'ClearanceOfficers',
94                                              roles=('SectionReader',))
95            students.manage_setLocalGroupRoles(groupid = 'CourseAdvisers',
96                                              roles=('SectionReader',))
97            students.manage_setLocalGroupRoles(groupid='MemberAdmins',
98                                         roles=('SectionOfficer',))
99            students.manage_setLocalGroupRoles(groupid='StudentsOfficers',
100                                         roles=('SectionOfficer',))
101            students.manage_setLocalGroupRoles(groupid = 'role:Student',
102                                              roles=('SectionReader',))
103        if accommodation is not None:
104            accommodation.manage_setLocalGroupRoles(groupid='role:Student',
105                                         roles=('SectionReader',))
106            accommodation.manage_setLocalGroupRoles(groupid='AccommodationOfficers',
107                                         roles=('SectionOfficer',))
108        if uploads is not None:
109            uploads.manage_setLocalGroupRoles(groupid='UploadOfficers',
110                                         roles=('SectionOfficer',))
111        if pins is not None:
112            uploads.manage_setLocalGroupRoles(groupid='AccessCodeOfficers',
113                                         roles=('SectionOfficer',))                                         
114    members = getattr(site.portal_directories,'members')
115    if members is not None:
116        members.manage_setLocalGroupRoles(groupid='MemberAdmins',
117                                         roles=('SectionOfficer',))
118    students = getattr(site.portal_directories,'students')
119    if students is not None:
120        students.manage_setLocalGroupRoles(groupid='MemberAdmins',
121                                         roles=('SectionOfficer',))
122    waeup_stacking_dir = getattr(site.portal_directories,'waeup_stacking_dir')
123    if waeup_stacking_dir is not None:
124        waeup_stacking_dir.manage_setLocalGroupRoles(groupid='MemberAdmins',
125                                         roles=('SectionOfficer',))
126
127##    pm.setLocalGroupRoles(campus.academics,['role:Authenticated',
128##                                           ],'SectionReader')
129    importWAeUPTable(site.portal_accommodation, '', context,'accommodation')
130    importWAeUPTable(site.courses_catalog, '', context,'courses_catalog')
131    importWAeUPTable(site.certificates_catalog, '', context,'certificates_catalog')
132    importWAeUPTable(site.payments_catalog, '', context,'payments_catalog')
133    importWAeUPTable(site.online_payments_import, '', context,'online_payments_import')
134    importWAeUPTable(site.portal_pins, '', context,'pins')
135    importWAeUPTable(site.portal_pumeresults, '', context,'pumeresults')
136    importWAeUPTable(site.returning_import, '', context,'returning_import')
137    importWAeUPTable(site.results_import, '', context,'results_import')
138    importWAeUPTable(site.students_catalog, '', context,'students_catalog')
139    importWAeUPTable(site.applicants_catalog, '', context,'applicants_catalog')
140    importWAeUPTable(site.course_results, '', context,'course_results')
141    importWAeUPTable(site.portal_catalog, '', context,'portal_catalog')
142    importWAeUPTable(site.portal_catalog_real, '', context,'portal_catalog_real')
143    importWAeUPTable(site.removed_student_ids, '', context,'removed_student_ids')
144
145    site.students_catalog.manage_setLocalGroupRoles(groupid='CampusOfficers',
146                                         roles=('SectionOfficer',))
147    site.payments_catalog.manage_setLocalGroupRoles(groupid='CampusOfficers',
148                                         roles=('SectionOfficer',))
149    site.applicants_catalog.manage_setLocalGroupRoles(groupid='CampusOfficers',
150                                         roles=('SectionOfficer',))
151    site.course_results.manage_setLocalGroupRoles(groupid='CampusOfficers',
152                                         roles=('SectionOfficer',))
153
154    site.portal_catalog.id = 'portal_catalog'
155    site.portal_catalog_real.id = 'portal_catalog_real'
156
157
158from Products.CPSCore.exportimport.catalog import CatalogToolXMLAdapter
159#from Products.GenericSetup.ZCatalog.exportimport import ZCatalogXMLAdapter
160
161from interfaces import IWAeUPTable
162
163class WAeUPTableXMLAdapter(CatalogToolXMLAdapter):
164#class WAeUPTableXMLAdapter(ZCatalogXMLAdapter):
165    __used_for__ = IWAeUPTable
166    _LOGGER_ID = 'waeup_table'
167
168##    def _importNode(self, node):
169##        """Import the object from the DOM node.
170##        """
171##        if self.environ.shouldPurge():
172##            self._purgeProperties()
173##            self._purgeObjects()
174##            self._purgeIndexes()
175##            self._purgeColumns()
176##
177##        self._logger.info('Catalog imported.')
178# This the XMLAdapter itself. It encodes the im- / export logic that is specific
179# to our tool. `im- / exportObjects` functions will find it thanks to the zope
180# components machinery and the associations made in the configure.zcml file.
181
182##class WAeUPXMLAdapter(XMLAdapterBase, PropertyManagerHelpers):
183##    """XML importer and exporter for the WAeUP tool.
184##
185##    Hence this XMLAdapter is really simple. To get more complete examples of
186##    what XMLAdapters are meant to do, please have a look at the
187##    CPSSkins.exportimport.py or CPSDirectory.exportimport.py files, for
188##    instance.
189##    """
190##
191##    adapts(IWAeUPTool, ISetupEnviron)
192##    implements(IBody)
193##
194##    _LOGGER_ID = NAME
195##    name = NAME
196##
197##    def _exportNode(self):
198##        """Export the object as a DOM node.
199##        """
200##        node = self._getObjectNode('object')
201##        node.appendChild(self._extractProperties())
202##        self._logger.info("WAeUP tool exported.")
203##        return node
204##
205##    def _importNode(self, node):
206##        """Import the object from the DOM node.
207##        """
208##        if self.environ.shouldPurge():
209##            self._purgeProperties()
210##        self._initProperties(node)
211##        self._logger.info("WAeUP tool imported.")
212##
Note: See TracBrowser for help on using the repository browser.