from StringIO import StringIO from zope.component import getUtility from zope.component import getMultiAdapter from plone.portlets.interfaces import IPortletAssignmentMapping from plone.portlets.interfaces import IPortletManager from portlets import memories, memorieslogin from plone.app.portlets import portlets from Products.CMFCore.utils import getToolByName def setupMemoriesPortlets(portal, out): leftColumn = getUtility(IPortletManager, name=u'plone.leftcolumn', context=portal) rightColumn = getUtility(IPortletManager, name=u'plone.rightcolumn', context=portal) left = getMultiAdapter((portal, leftColumn,), IPortletAssignmentMapping, context=portal) right = getMultiAdapter((portal, rightColumn,), IPortletAssignmentMapping, context=portal) if u'portlets.memoriesmemories' not in left: print >> out, "Adding links portlet to the left column" left[u'portlets.memoriesmemories'] = memories.Assignment() order = [left.keys()[-1]]+left.keys()[:-1] left.updateOrder(list(order)) if u'portlets.memorieslogin' not in left: print >> out, "Adding memorieslogin portlet to the left column" left[u'portlets.memorieslogin'] = memorieslogin.Assignment() try: del left[u'navigation'] del left[u'login'] except KeyError: pass try: del right[u'review'] del right[u'news'] del right[u'events'] del right['calendar'] except KeyError: pass def setupMemberAreaOptions(portal, out): context = portal mtool = getToolByName(context, 'portal_membership') if not mtool.getMemberareaCreationFlag(): mtool.setMemberareaCreationFlag() mtool.setMemberAreaType('MemoriesFolder') def setupMemoriesWorkflow(portal, out): context = portal wtool = getToolByName(context, 'portal_workflow') # MemoriesFolder must have only published state wtool.setChainForPortalTypes(('MemoriesFolder',), 'one_state_workflow') # Types that are added into memories folder must use own workflow wtool.setChainForPortalTypes(('Image','Announcement',), 'simple_memories_workflow') # XXX This one might have to be done better #try: # wtool.setChainForPortalTypes(('GeoLocation',), 'simple_memories_workflow') #except KeyError: # pass def setupMemoriesActions(portal, out): context = portal atool = getToolByName(context, 'portal_actions') if atool.user.getObjectPosition('plone_setup') == 8: atool.user.moveObjectsUp(['plone_setup'],3) def importVarious(context): if context.readDataFile('memories_import.txt') is None: return site = context.getSite() out = StringIO() setupMemoriesPortlets(site, out) setupMemberAreaOptions(site, out) setupMemoriesWorkflow(site, out) setupMemoriesActions(site, out) # XXX This does not seem to be needed atm def createContent(context): if context.readDataFile("memories_import.txt") is None: print "===== SKIPPING createContent =====" return