source: WAeUP_SRP/trunk/exportimport.py @ 380

Last change on this file since 380 was 363, checked in by lregebro, 18 years ago

Accomodation mapping storage tool.

File size: 3.7 KB
Line 
1#-*- mode: python; mode: fold -*-
2# $Id: exportimport.py 31640 2006-01-15 19:22:29Z ogrisel $
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.component import adapts
18from zope.interface import implements
19
20# Standard GenericSetup base classes and functions
21from Products.GenericSetup.utils import exportObjects
22from Products.GenericSetup.utils import importObjects
23from Products.GenericSetup.utils import XMLAdapterBase
24from Products.GenericSetup.utils import PropertyManagerHelpers
25
26from Products.CMFCore.utils import getToolByName
27
28# GenericSetup multi adapts a class that implement IWAeUP and a particular
29# ISetupEnvironment to and IBody (piece of XML configuration).
30from Products.GenericSetup.interfaces import IBody
31from Products.GenericSetup.interfaces import ISetupEnviron
32from Products.WAeUP_SRP.interfaces import IWAeUPTool
33import Globals
34p_home = Globals.package_home(globals())
35i_home = Globals.INSTANCE_HOME
36
37TOOL = 'portal_waeup'
38NAME = 'waeup'
39
40def exportWAeUP(context):
41    """Export our WAeUP tool configuration
42    """
43    site = context.getSite()
44    tool = getattr(context,"campus",None)
45    if tool is None:
46        logger = context.getLogger(NAME)
47        logger.info("Nothing to export.")
48        return
49    exportObjects(tool, '', context)
50
51def importWAeUP(context):
52    """Import WAeUP tool configuration
53    """
54    site = context.getSite()
55    pm = site.portal_membership
56    pm.setLocalGroupRoles(site,['role:Authenticated',],'SectionReader')
57
58    importObjects(site.portal_accomodation, '', context)
59   
60##    if hasattr(site,'campus'):
61##        pm.setLocalGroupRoles(site.campus,['role:Authenticated',],'SectionReader')
62    #setupStructure(site,context)
63    #import pdb; pdb.set_trace()
64    #site = context.getSite()
65    #tool = getToolByName(site, TOOL)
66    #importObjects(tool, '', context)
67
68
69from Products.GenericSetup.ZCatalog.exportimport import ZCatalogXMLAdapter
70
71from interfaces import IWAeUPTable
72
73class WAeUPTableXMLAdapter(ZCatalogXMLAdapter):
74   
75    __used_for__ = IWAeUPTable
76
77    _LOGGER_ID = 'waeup_table'
78
79    name = 'accomodation'
80
81# This the XMLAdapter itself. It encodes the im- / export logic that is specific
82# to our tool. `im- / exportObjects` functions will find it thanks to the zope
83# components machinery and the associations made in the configure.zcml file.
84
85##class WAeUPXMLAdapter(XMLAdapterBase, PropertyManagerHelpers):
86##    """XML importer and exporter for the WAeUP tool.
87##
88##    Hence this XMLAdapter is really simple. To get more complete examples of
89##    what XMLAdapters are meant to do, please have a look at the
90##    CPSSkins.exportimport.py or CPSDirectory.exportimport.py files, for
91##    instance.
92##    """
93##
94##    adapts(IWAeUPTool, ISetupEnviron)
95##    implements(IBody)
96##
97##    _LOGGER_ID = NAME
98##    name = NAME
99##
100##    def _exportNode(self):
101##        """Export the object as a DOM node.
102##        """
103##        node = self._getObjectNode('object')
104##        node.appendChild(self._extractProperties())
105##        self._logger.info("WAeUP tool exported.")
106##        return node
107##
108##    def _importNode(self, node):
109##        """Import the object from the DOM node.
110##        """
111##        if self.environ.shouldPurge():
112##            self._purgeProperties()
113##        self._initProperties(node)
114##        self._logger.info("WAeUP tool imported.")
115##
Note: See TracBrowser for help on using the repository browser.