Esempio n. 1
0
def form_adapter_pasted(form_adapter, event):
    """If an action adapter is pasted into the form, add it to the form's
       list of active adapters. We only need to do anything if the action
       adapter isn't newly created in the portal_factory.
    """
    form_adapter = aq_inner(form_adapter)
    if IFactoryTool.providedBy(aq_parent(aq_parent(form_adapter))):
        return

    form = aq_parent(form_adapter)
    adapters = list(form.actionAdapter)
    if form_adapter.id not in adapters:
        adapters.append(form_adapter.id)
        form.setActionAdapter(adapters)
Esempio n. 2
0
def getSubsiteRoot(context, relativeRoot=None):
    """Get the path to the root of the navigation tree. If context or one of
    its parents until (but not including) the portal root implements
    ISubsiteEnhanced, return this.

    Otherwise, if an explicit root is set in navtree_properties or given as
    relativeRoot, use this. If the property is not set or is set to '/', use
    the portal root.
    """

    portal_url = getToolByName(context, 'portal_url')

    if not relativeRoot:
        portal_properties = getToolByName(context, 'portal_properties')
        navtree_properties = getattr(portal_properties, 'navtree_properties')
        relativeRoot = navtree_properties.getProperty('root', None)

    portal = portal_url.getPortalObject()
    obj = context
    while (not ISubsiteEnhanced.providedBy(obj)
           and aq_base(obj) is not aq_base(portal)):
        # XXX a bit ugly: if this method is called with a context from inside
        # the portal_factory, we cannot use the parent() method, as it calls
        # aq_parent on aq_inner of the object. This directly returns the main
        # portal
        if IFactoryTool.providedBy(obj):
            obj = aq_parent(obj)
        else:
            obj = utils.parent(obj)
    if (ISubsiteEnhanced.providedBy(obj)
        and aq_base(obj) is not aq_base(portal)):
        return '/'.join(obj.getPhysicalPath())

    rootPath = relativeRoot
    portalPath = portal_url.getPortalPath()
    # contextPath = '/'.join(context.getPhysicalPath())

    if rootPath:
        if rootPath == '/':
            return portalPath
        else:
            if len(rootPath) > 1 and rootPath[0] == '/':
                return portalPath + rootPath
            else:
                return portalPath

    # Fall back on the portal root
    if not rootPath:
        return portalPath
Esempio n. 3
0
def form_adapter_moved(form_adapter, event):
    """If an active action adapter is renamed, keep it active.

    Instead of renaming, some more moves are possible, like moving from
    one form to another, though that is unlikely.  We can handle it
    all though.

    Note that in a pure rename, event.oldParent is the same as
    event.newParent.  One of them could be None.  They may not always
    be forms.
    """
    form_adapter = aq_inner(form_adapter)
    if IFactoryTool.providedBy(aq_parent(aq_parent(form_adapter))):
        return

    if not event.oldParent:
        # We cannot know if the adapter was active, so we do nothing.
        pass
    try:
        adapters = list(event.oldParent.actionAdapter)
    except AttributeError:
        # no Form Folder, probably factory tool
        return
    was_active = event.oldName in adapters
    if was_active:
        # deactivate the old name
        adapters.remove(event.oldName)
        event.oldParent.setActionAdapter(adapters)
    if not was_active:
        # nothing to do
        return
    if event.newParent:
        try:
            adapters = list(event.newParent.actionAdapter)
        except AttributeError:
            # no Form Folder, probably factory tool
            return
        else:
            if event.newName not in adapters:
                adapters.append(event.newName)
                event.newParent.setActionAdapter(adapters)