1
2
3
4
5
6
7
8
9
10
11
12
13 """ CMFDefault setup handlers.
14
15 """
16 from StringIO import StringIO
17
18 from zope.interface import alsoProvides, directlyProvides, directlyProvidedBy
19 from zope.component import getUtility
20 from zope.app.component.hooks import setSite
21 from zope.app.component.interfaces import ISite, IPossibleSite
22 from Products.CMFCore.utils import getToolByName
23 from Products.Five.site.localsite import enableLocalSiteHook
24
25 import interfaces
26 from preferences import PlatecomManagementContentTypes
27 from config import HAS_PLONE3
28
30 """Ensure the given context implements ISite. The importance of
31 this method is that it will ensure the given context is an ISite
32 regardless of the Zope version (Zope 2.9 had a really hacked up
33 SiteManager mechanism we have to account for).
34
35 >>> from zope.app.component.interfaces import ISite, IPossibleSite
36 >>> from OFS.Folder import Folder
37 >>> if not IPossibleSite.implementedBy(Folder):
38 ... from zope import interface
39 ... from Products.Five.site.metaconfigure import (FiveSite,
40 ... classSiteHook)
41 ... classSiteHook(Folder, FiveSite)
42 ... interface.classImplements(Folder, IPossibleSite)
43 >>> om = Folder('foo')
44
45 >>> ISite.providedBy(om)
46 False
47
48 >>> from iccommunity.core.setuphandlers import ensure_site
49 >>> ensure_site(om)
50 >>> ISite.providedBy(om)
51 True
52
53 """
54 if not IPossibleSite.providedBy(context):
55 if hasattr(context, 'getPhysicalPath'):
56 p = '/'.join(context.getPhysicalPath())
57 elif hasattr(context, 'getId'):
58 p = context.getId()
59 elif hasattr(context, 'id'):
60 p = id
61 else:
62 p = str(context)
63
64 raise TypeError('The object, "%s", is not an IPossibleSite' % p)
65
66 if not ISite.providedBy(context):
67 enableLocalSiteHook(context)
68 setSite(context)
69
70 if not ISite.providedBy(context):
71 raise TypeError('Somehow trying to configure "%s" as an ISite '
72 'has failed' % '/'.join(context.getPhysicalPath()))
73
102
104 """ Import various settings.
105
106 This provisional handler will be removed again as soon as full handlers
107 are implemented for these steps.
108 """
109 site = context.getSite()
110 out = StringIO()
111 logger = context.getLogger("iccommunity.core")
112
113 ensure_site(site)
114 setup_site(site, out)
115
116 print >> out, 'Various settings imported.'
117
118 logger.info(out.getvalue())
119 return out.getvalue()
120
122 """ Import various settings.
123
124 This provisional handler will be removed again as soon as full handlers
125 are implemented for these steps.
126 """
127 site = context.getSite()
128 out = StringIO()
129 logger = context.getLogger("iccommunity.langfallback")
130
131 print >> out, 'Various settings unimported.'
132
133 logger.info(out.getvalue())
134 return out.getvalue()
135