File: factorytool.py

package info (click to toggle)
zope-cmfplone 2.5.1-4etch3
  • links: PTS
  • area: main
  • in suites: etch
  • size: 7,752 kB
  • ctags: 5,237
  • sloc: python: 28,264; xml: 3,723; php: 129; makefile: 99; sh: 2
file content (81 lines) | stat: -rw-r--r-- 2,391 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
from Products.CMFPlone.interfaces import IFactoryTool
from Products.GenericSetup.utils import XMLAdapterBase
from Products.GenericSetup.utils import importObjects
from Products.GenericSetup.utils import exportObjects
from Products.CMFCore.utils import getToolByName

try:
    set()
except NameError:
    from sets import Set as set


class PortalFactoryXMLAdapter(XMLAdapterBase):
    """In- and exporter for FactoryTool.
    """

    __used_for__ = IFactoryTool

    _LOGGER_ID = name = 'factorytool'

    def _exportNode(self):
        """Export the object as a DOM node.
        """
        node = self._getObjectNode("object")
        node.appendChild(self._extractFactoryToolSettings())

        self._logger.info("FactoryTool settings exported.")
        return node

    def _importNode(self, node):
        if self.environ.shouldPurge():
            self._purgeFactoryToolSettings()

        self._initFactoryToolSettings(node)
        self._logger.info("FactoryTool settings imported.")

    def _purgeFactoryToolSettings(self):
        self.context.manage_setPortalFactoryTypes(listOfTypeIds=[])


    def _initFactoryToolSettings(self, node):
        for child in node.childNodes:
            if child.nodeName=="factorytypes":
                types=set(self.context.getFactoryTypes())
                for type in child.getElementsByTagName("type"):
                    types.add(type.getAttribute("portal_type"))
                self.context.manage_setPortalFactoryTypes(
                                    listOfTypeIds=list(types))


    def _extractFactoryToolSettings(self):
        node=self._doc.createElement("factorytypes")
        for type in self.context.getFactoryTypes():
            child=self._doc.createElement("type")
            child.setAttribute("portal_type", type)
            node.appendChild(child)

        return node


def importFactoryTool(context):
    """Import Factory Tool configuration.
    """
    site = context.getSite()
    tool = getToolByName(site, 'portal_factory')

    importObjects(tool, '', context)


def exportFactoryTool(context):
    """Export Factory Tool configuration.
    """
    site = context.getSite()
    tool = getToolByName(site, 'portal_factory', None)
    if tool is None:
        logger = context.getLogger("factorytool")
        logger.info("Nothing to export.")
        return

    exportObjects(tool, '', context)