[200] | 1 | #-*- mode: python; mode: fold -*- |
---|
[486] | 2 | # $Id: exportimport.py 2094 2007-08-13 12:01:11Z joachim $ |
---|
[199] | 3 | """WAeUP Tool XML Adapter. |
---|
| 4 | |
---|
| 5 | An XML adapter tells the GenericSetup machinery howto im- / export persistent |
---|
| 6 | configuration that is relative to a specific CMF component such as our WAeUP |
---|
| 7 | Tool. |
---|
| 8 | |
---|
| 9 | GenericSetup uses the Zope3 interfaces and components machinery to find the |
---|
| 10 | right XML adapter for the right object. This is why we flagged our waeup tool |
---|
| 11 | with the `implements(IWAeUPTool)` class attribute and made an adapter |
---|
| 12 | association in the `configure.zcml` file. |
---|
| 13 | """ |
---|
[238] | 14 | import csv,re |
---|
[199] | 15 | |
---|
| 16 | # Zope3 component architecture |
---|
[502] | 17 | from zope.app import zapi |
---|
[199] | 18 | from zope.component import adapts |
---|
| 19 | from zope.interface import implements |
---|
| 20 | |
---|
| 21 | # Standard GenericSetup base classes and functions |
---|
| 22 | from Products.GenericSetup.utils import exportObjects |
---|
| 23 | from Products.GenericSetup.utils import importObjects |
---|
| 24 | from Products.GenericSetup.utils import XMLAdapterBase |
---|
| 25 | from Products.GenericSetup.utils import PropertyManagerHelpers |
---|
| 26 | |
---|
| 27 | from 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). |
---|
| 31 | from Products.GenericSetup.interfaces import IBody |
---|
| 32 | from Products.GenericSetup.interfaces import ISetupEnviron |
---|
[274] | 33 | from Products.WAeUP_SRP.interfaces import IWAeUPTool |
---|
[238] | 34 | import Globals |
---|
| 35 | p_home = Globals.package_home(globals()) |
---|
| 36 | i_home = Globals.INSTANCE_HOME |
---|
[199] | 37 | |
---|
| 38 | TOOL = 'portal_waeup' |
---|
| 39 | NAME = 'waeup' |
---|
| 40 | |
---|
[502] | 41 | def 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] | 60 | def 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 | |
---|
| 71 | def 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) |
---|
[1414] | 81 | campus.manage_setLocalGroupRoles(groupid='CampusOfficers', |
---|
[1432] | 82 | roles=('SectionOfficer',)) |
---|
[949] | 83 | if academics is not None: |
---|
[955] | 84 | academics.manage_setLocalGroupRoles(groupid='role:Authenticated', |
---|
[926] | 85 | roles=('SectionReader',)) |
---|
[1414] | 86 | academics.manage_setLocalGroupRoles(groupid='AcademicsOfficers', |
---|
[1432] | 87 | roles=('SectionOfficer',)) |
---|
[949] | 88 | if students is not None: |
---|
[962] | 89 | students.manage_setLocalGroupRoles(groupid = 'ClearanceOfficers', |
---|
[955] | 90 | roles=('SectionReader',)) |
---|
[1515] | 91 | students.manage_setLocalGroupRoles(groupid = 'CourseAdvisers', |
---|
[1625] | 92 | roles=('SectionReader',)) |
---|
[1221] | 93 | students.manage_setLocalGroupRoles(groupid='MemberAdmins', |
---|
[1414] | 94 | roles=('SectionOfficer',)) |
---|
| 95 | students.manage_setLocalGroupRoles(groupid='StudentsOfficers', |
---|
[1432] | 96 | roles=('SectionOfficer',)) |
---|
[962] | 97 | students.manage_setLocalGroupRoles(groupid = 'role:Student', |
---|
| 98 | roles=('SectionReader',)) |
---|
[963] | 99 | if accommodation is not None: |
---|
| 100 | accommodation.manage_setLocalGroupRoles(groupid='role:Student', |
---|
[1221] | 101 | roles=('SectionReader',)) |
---|
[1414] | 102 | accommodation.manage_setLocalGroupRoles(groupid='AccommodationOfficers', |
---|
[1432] | 103 | roles=('SectionOfficer',)) |
---|
[955] | 104 | members = getattr(site.portal_directories,'members') |
---|
| 105 | if members is not None: |
---|
[957] | 106 | members.manage_setLocalGroupRoles(groupid='MemberAdmins', |
---|
[955] | 107 | roles=('SectionOfficer',)) |
---|
[1432] | 108 | students = getattr(site.portal_directories,'students') |
---|
| 109 | if students is not None: |
---|
| 110 | students.manage_setLocalGroupRoles(groupid='MemberAdmins', |
---|
[1433] | 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', |
---|
[1515] | 115 | roles=('SectionOfficer',)) |
---|
[956] | 116 | |
---|
[926] | 117 | ## pm.setLocalGroupRoles(campus.academics,['role:Authenticated', |
---|
| 118 | ## ],'SectionReader') |
---|
[502] | 119 | importWAeUPTable(site.portal_accommodation, '', context,'accommodation') |
---|
[1146] | 120 | importWAeUPTable(site.courses_catalog, '', context,'courses_catalog') |
---|
| 121 | importWAeUPTable(site.payments_catalog, '', context,'payments_catalog') |
---|
[1625] | 122 | importWAeUPTable(site.online_payments_import, '', context,'online_payments_import') |
---|
[502] | 123 | importWAeUPTable(site.portal_pins, '', context,'pins') |
---|
[966] | 124 | importWAeUPTable(site.portal_pumeresults, '', context,'pumeresults') |
---|
[1151] | 125 | importWAeUPTable(site.returning_import, '', context,'returning_import') |
---|
[1146] | 126 | importWAeUPTable(site.results_import, '', context,'results_import') |
---|
[2086] | 127 | importWAeUPTable(site.students_catalog, '', context,'students_catalog') |
---|
[2094] | 128 | importWAeUPTable(site.applicants_catalog, '', context,'applicants_catalog') |
---|
[2086] | 129 | importWAeUPTable(site.course_results, '', context,'course_results') |
---|
[1935] | 130 | importWAeUPTable(site.portal_catalog_real, '', context,'portal_catalog_real') |
---|
[950] | 131 | |
---|
[502] | 132 | from Products.CPSCore.exportimport.catalog import CatalogToolXMLAdapter |
---|
| 133 | #from Products.GenericSetup.ZCatalog.exportimport import ZCatalogXMLAdapter |
---|
[363] | 134 | |
---|
| 135 | from interfaces import IWAeUPTable |
---|
| 136 | |
---|
[502] | 137 | class WAeUPTableXMLAdapter(CatalogToolXMLAdapter): |
---|
| 138 | #class WAeUPTableXMLAdapter(ZCatalogXMLAdapter): |
---|
[363] | 139 | __used_for__ = IWAeUPTable |
---|
| 140 | _LOGGER_ID = 'waeup_table' |
---|
| 141 | |
---|
[502] | 142 | ## def _importNode(self, node): |
---|
| 143 | ## """Import the object from the DOM node. |
---|
| 144 | ## """ |
---|
| 145 | ## if self.environ.shouldPurge(): |
---|
| 146 | ## self._purgeProperties() |
---|
| 147 | ## self._purgeObjects() |
---|
| 148 | ## self._purgeIndexes() |
---|
| 149 | ## self._purgeColumns() |
---|
| 150 | ## |
---|
| 151 | ## self._logger.info('Catalog imported.') |
---|
[199] | 152 | # This the XMLAdapter itself. It encodes the im- / export logic that is specific |
---|
| 153 | # to our tool. `im- / exportObjects` functions will find it thanks to the zope |
---|
| 154 | # components machinery and the associations made in the configure.zcml file. |
---|
| 155 | |
---|
[282] | 156 | ##class WAeUPXMLAdapter(XMLAdapterBase, PropertyManagerHelpers): |
---|
| 157 | ## """XML importer and exporter for the WAeUP tool. |
---|
| 158 | ## |
---|
| 159 | ## Hence this XMLAdapter is really simple. To get more complete examples of |
---|
| 160 | ## what XMLAdapters are meant to do, please have a look at the |
---|
| 161 | ## CPSSkins.exportimport.py or CPSDirectory.exportimport.py files, for |
---|
| 162 | ## instance. |
---|
| 163 | ## """ |
---|
| 164 | ## |
---|
| 165 | ## adapts(IWAeUPTool, ISetupEnviron) |
---|
| 166 | ## implements(IBody) |
---|
| 167 | ## |
---|
| 168 | ## _LOGGER_ID = NAME |
---|
| 169 | ## name = NAME |
---|
| 170 | ## |
---|
| 171 | ## def _exportNode(self): |
---|
| 172 | ## """Export the object as a DOM node. |
---|
| 173 | ## """ |
---|
| 174 | ## node = self._getObjectNode('object') |
---|
| 175 | ## node.appendChild(self._extractProperties()) |
---|
| 176 | ## self._logger.info("WAeUP tool exported.") |
---|
| 177 | ## return node |
---|
| 178 | ## |
---|
| 179 | ## def _importNode(self, node): |
---|
| 180 | ## """Import the object from the DOM node. |
---|
| 181 | ## """ |
---|
| 182 | ## if self.environ.shouldPurge(): |
---|
| 183 | ## self._purgeProperties() |
---|
| 184 | ## self._initProperties(node) |
---|
| 185 | ## self._logger.info("WAeUP tool imported.") |
---|
| 186 | ## |
---|