Skip to content

Instantly share code, notes, and snippets.

@jensens
Created March 2, 2011 16:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jensens/851167 to your computer and use it in GitHub Desktop.
Save jensens/851167 to your computer and use it in GitHub Desktop.
actions to set a Navigation Root
from zope.interface import Interface
from zope.interface import directlyProvides
from zope.interface import noLongerProvides
from Products.Five.browser import BrowserView
from Products.CMFPlone.interfaces import INavigationRoot
from Products.CMFPlone import PloneMessageFactory as _
class IPossibleNavigationRoot(Interface):
pass
class ActionsView(BrowserView):
def enableNavigationRoot(self):
directlyProvides(self.context, INavigationRoot)
self.context.portal_catalog.reindexObject(self.context,
idxs=['object_provides'],
update_metadata=1)
self.context.plone_utils.addPortalMessage(
_(u'Enabled Navigation Root.'))
self.request.response.redirect(self.context.absolute_url())
def disableNavigationRoot(self):
noLongerProvides(self.context, INavigationRoot)
self.context.portal_catalog.reindexObject(self.context,
idxs=['object_provides'],
update_metadata=1)
self.context.plone_utils.addPortalMessage(
_(u'Disabled Navigation Root.'))
self.request.response.redirect(self.context.absolute_url())
def isPossibleToEnableNavigationRoot(self):
return IPossibleNavigationRoot.providedBy(self.context) \
and not INavigationRoot.providedBy(self.context)
def isPossibleToDisableNavigationRoot(self):
return IPossibleNavigationRoot.providedBy(self.context) \
and INavigationRoot.providedBy(self.context)
<?xml version="1.0"?>
<object name="portal_actions" meta_type="Plone Actions Tool"
xmlns:i18n="http://xml.zope.org/namespaces/i18n">
<object name="object_buttons" meta_type="CMF Action Category">
<object name="enableNavigation"
meta_type="CMF Action"
i18n:domain="kup.site.e2p">
<property name="title" i18n:translate="">
Enable Navigation
</property>
<property name="description" i18n:translate="">
Activate Folder as Navigation
</property>
<property name="url_expr">
string:${object/absolute_url}/@@enable-NavigationRoot
</property>
<property name="icon_expr"></property>
<property name="available_expr">
object/@@is-possible-to-enable-NavigationRoot
</property>
<property name="permissions">
<element value="Manage portal" />
</property>
<property name="visible">True</property>
</object>
<object name="disableNavigation"
meta_type="CMF Action"
i18n:domain="kup.site.e2p">
<property name="title" i18n:translate="">
Disables Navigation
</property>
<property name="description" i18n:translate="">
Deactivates Folder as Navigation
</property>
<property name="url_expr">
string:${object/absolute_url}/@@disable-NavigationRoot
</property>
<property name="icon_expr"></property>
<property name="available_expr">
object/@@is-possible-to-disable-NavigationRoot
</property>
<property name="permissions">
<element value="Manage portal" />
</property>
<property name="visible">True</property>
</object>
</object>
</object>
<configure xmlns="http://namespaces.zope.org/zope"
xmlns:browser="http://namespaces.zope.org/browser"
xmlns:five="http://namespaces.zope.org/five">
<five:implements
class="Products.ATContentTypes.content.folder.ATFolder"
interface=".actions.IPossibleNavigationRoot" />
<browser:page
name="enable-NavigationRoot"
attribute="enableNavigationRoot"
for=".actions.IPossibleNavigationRoot"
class=".actions.ActionsView"
permission="cmf.ManagePortal"
/>
<browser:page
name="disable-NavigationRoot"
attribute="disableNavigationRoot"
for=".actions.IPossibleNavigationRoot"
class=".actions.ActionsView"
permission="cmf.ManagePortal"
/>
<browser:page
name="is-possible-to-enable-NavigationRoot"
attribute="isPossibleToEnableNavigationRoot"
for="*"
class=".actions.ActionsView"
permission="cmf.ManagePortal"
/>
<browser:page
name="is-possible-to-disable-NavigationRoot"
attribute="isPossibleToDisableNavigationRoot"
for="*"
class=".actions.ActionsView"
permission="cmf.ManagePortal"
/>
</configure>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment