source: WAeUP_SRP/trunk/exportimport.py @ 2092

Last change on this file since 2092 was 2086, checked in by joachim, 17 years ago

add course_results catalog

  • Property svn:keywords set to Id
File size: 7.7 KB
Line 
1#-*- mode: python; mode: fold -*-
2# $Id: exportimport.py 2086 2007-08-03 06:16:48Z joachim $
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        campus.manage_setLocalGroupRoles(groupid='CampusOfficers',
82                                         roles=('SectionOfficer',))
83        if academics is not None:
84            academics.manage_setLocalGroupRoles(groupid='role:Authenticated',
85                                         roles=('SectionReader',))
86            academics.manage_setLocalGroupRoles(groupid='AcademicsOfficers',
87                                         roles=('SectionOfficer',))
88        if students is not None:
89            students.manage_setLocalGroupRoles(groupid = 'ClearanceOfficers',
90                                              roles=('SectionReader',))
91            students.manage_setLocalGroupRoles(groupid = 'CourseAdvisers',
92                                              roles=('SectionReader',))
93            students.manage_setLocalGroupRoles(groupid='MemberAdmins',
94                                         roles=('SectionOfficer',))
95            students.manage_setLocalGroupRoles(groupid='StudentsOfficers',
96                                         roles=('SectionOfficer',))
97            students.manage_setLocalGroupRoles(groupid = 'role:Student',
98                                              roles=('SectionReader',))
99        if accommodation is not None:
100            accommodation.manage_setLocalGroupRoles(groupid='role:Student',
101                                         roles=('SectionReader',))
102            accommodation.manage_setLocalGroupRoles(groupid='AccommodationOfficers',
103                                         roles=('SectionOfficer',))
104    members = getattr(site.portal_directories,'members')
105    if members is not None:
106        members.manage_setLocalGroupRoles(groupid='MemberAdmins',
107                                         roles=('SectionOfficer',))
108    students = getattr(site.portal_directories,'students')
109    if students is not None:
110        students.manage_setLocalGroupRoles(groupid='MemberAdmins',
111                                         roles=('SectionOfficer',))
112    waeup_stacking_dir = getattr(site.portal_directories,'waeup_stacking_dir')
113    if waeup_stacking_dir is not None:
114        waeup_stacking_dir.manage_setLocalGroupRoles(groupid='MemberAdmins',
115                                         roles=('SectionOfficer',))
116
117##    pm.setLocalGroupRoles(campus.academics,['role:Authenticated',
118##                                           ],'SectionReader')
119    importWAeUPTable(site.portal_accommodation, '', context,'accommodation')
120    importWAeUPTable(site.courses_catalog, '', context,'courses_catalog')
121    importWAeUPTable(site.payments_catalog, '', context,'payments_catalog')
122    importWAeUPTable(site.online_payments_import, '', context,'online_payments_import')
123    importWAeUPTable(site.portal_pins, '', context,'pins')
124    importWAeUPTable(site.portal_pumeresults, '', context,'pumeresults')
125    importWAeUPTable(site.returning_import, '', context,'returning_import')
126    importWAeUPTable(site.results_import, '', context,'results_import')
127    importWAeUPTable(site.students_catalog, '', context,'students_catalog')
128    importWAeUPTable(site.course_results, '', context,'course_results')
129    importWAeUPTable(site.portal_catalog_real, '', context,'portal_catalog_real')
130
131from Products.CPSCore.exportimport.catalog import CatalogToolXMLAdapter
132#from Products.GenericSetup.ZCatalog.exportimport import ZCatalogXMLAdapter
133
134from interfaces import IWAeUPTable
135
136class WAeUPTableXMLAdapter(CatalogToolXMLAdapter):
137#class WAeUPTableXMLAdapter(ZCatalogXMLAdapter):
138    __used_for__ = IWAeUPTable
139    _LOGGER_ID = 'waeup_table'
140
141##    def _importNode(self, node):
142##        """Import the object from the DOM node.
143##        """
144##        if self.environ.shouldPurge():
145##            self._purgeProperties()
146##            self._purgeObjects()
147##            self._purgeIndexes()
148##            self._purgeColumns()
149##
150##        self._logger.info('Catalog imported.')
151# This the XMLAdapter itself. It encodes the im- / export logic that is specific
152# to our tool. `im- / exportObjects` functions will find it thanks to the zope
153# components machinery and the associations made in the configure.zcml file.
154
155##class WAeUPXMLAdapter(XMLAdapterBase, PropertyManagerHelpers):
156##    """XML importer and exporter for the WAeUP tool.
157##
158##    Hence this XMLAdapter is really simple. To get more complete examples of
159##    what XMLAdapters are meant to do, please have a look at the
160##    CPSSkins.exportimport.py or CPSDirectory.exportimport.py files, for
161##    instance.
162##    """
163##
164##    adapts(IWAeUPTool, ISetupEnviron)
165##    implements(IBody)
166##
167##    _LOGGER_ID = NAME
168##    name = NAME
169##
170##    def _exportNode(self):
171##        """Export the object as a DOM node.
172##        """
173##        node = self._getObjectNode('object')
174##        node.appendChild(self._extractProperties())
175##        self._logger.info("WAeUP tool exported.")
176##        return node
177##
178##    def _importNode(self, node):
179##        """Import the object from the DOM node.
180##        """
181##        if self.environ.shouldPurge():
182##            self._purgeProperties()
183##        self._initProperties(node)
184##        self._logger.info("WAeUP tool imported.")
185##
Note: See TracBrowser for help on using the repository browser.