add portlet to navigate between classifying folders (#3779)
This commit is contained in:
parent
96ac0c4c41
commit
4703556bbe
|
@ -5,6 +5,7 @@
|
|||
xmlns:i18n="http://namespaces.zope.org/i18n"
|
||||
xmlns:genericsetup="http://namespaces.zope.org/genericsetup"
|
||||
xmlns:browser="http://namespaces.zope.org/browser"
|
||||
xmlns:plone="http://namespaces.plone.org/plone"
|
||||
i18n_domain="pfwbged.folder">
|
||||
|
||||
<five:registerPackage package="." initialize=".initialize" />
|
||||
|
@ -38,4 +39,13 @@
|
|||
permission="zope2.View"
|
||||
/>
|
||||
|
||||
<plone:portlet
|
||||
name="pfwbged.folder.portlet.Navigation"
|
||||
interface=".portlet.INavigationPortlet"
|
||||
assignment=".portlet.Assignment"
|
||||
renderer=".portlet.Renderer"
|
||||
addview=".portlet.AddForm"
|
||||
editview=".portlet.EditForm"
|
||||
/>
|
||||
|
||||
</configure>
|
||||
|
|
|
@ -65,6 +65,40 @@ class Folder(Container):
|
|||
""" """
|
||||
implements(IFolder)
|
||||
|
||||
def parent_folders(self):
|
||||
parents = []
|
||||
for id, item in self.contentItems():
|
||||
if not ILink.providedBy(item):
|
||||
continue
|
||||
parents.append(item.folder.to_object)
|
||||
return parents
|
||||
|
||||
def child_folders(self):
|
||||
intids = component.getUtility(IIntIds)
|
||||
intid_catalog = component.getUtility(ICatalog)
|
||||
try:
|
||||
intid = intids.getId(self)
|
||||
except KeyError:
|
||||
return []
|
||||
|
||||
children = []
|
||||
sm = getSecurityManager()
|
||||
for item in intid_catalog.findRelations({
|
||||
'to_id': intid,
|
||||
'from_interfaces_flattened': ILink}):
|
||||
if item.isBroken():
|
||||
continue
|
||||
|
||||
link = item.from_object
|
||||
if not sm.checkPermission('View', link):
|
||||
continue
|
||||
|
||||
document = aq_parent(link)
|
||||
if IFolder.providedBy(document):
|
||||
children.append(IContentListingObject(document))
|
||||
|
||||
return children
|
||||
|
||||
grok.templatedir('templates')
|
||||
grok.context(IDexterityContainer)
|
||||
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
<dl class="portlet portletFolder">
|
||||
<dt class="portletHeader">
|
||||
<span class="portletTopLeft"></span>
|
||||
<span class="portletTopRight"></span>
|
||||
</dt>
|
||||
<dd class="portletItem">
|
||||
|
||||
<ul>
|
||||
<li tal:repeat="item context/parent_folders"><a
|
||||
tal:attributes="href item/absolute_url" tal:content="item/Title">parent</a></li>
|
||||
</ul>
|
||||
|
||||
<strong tal:content="context/Title">title</strong>
|
||||
|
||||
<ul>
|
||||
<li tal:repeat="item context/child_folders"><a
|
||||
tal:attributes="href item/getURL" tal:content="item/Title">child</a></li>
|
||||
</ul>
|
||||
|
||||
</dd>
|
||||
<dd class="portletFooter">
|
||||
<span class="portletBottomLeft"></span>
|
||||
<span class="portletBottomRight"></span>
|
||||
</dd>
|
||||
</dl>
|
|
@ -0,0 +1,45 @@
|
|||
from zope import schema
|
||||
from zope.formlib import form
|
||||
from zope.interface import implements
|
||||
from zope.component import getMultiAdapter
|
||||
from plone.app.portlets.portlets import base
|
||||
from plone.portlets.interfaces import IPortletDataProvider
|
||||
from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
|
||||
from Products.CMFCore.utils import getToolByName
|
||||
|
||||
from . import _
|
||||
from folder import IFolder
|
||||
|
||||
|
||||
class INavigationPortlet(IPortletDataProvider):
|
||||
''' '''
|
||||
|
||||
|
||||
class Assignment(base.Assignment):
|
||||
implements(INavigationPortlet)
|
||||
|
||||
|
||||
class Renderer(base.Renderer):
|
||||
render = ViewPageTemplateFile('portlet.pt')
|
||||
|
||||
def title(self):
|
||||
return _('Folder Navigation')
|
||||
|
||||
@property
|
||||
def available(self):
|
||||
return IFolder.providedBy(self.context)
|
||||
|
||||
|
||||
class AddForm(base.AddForm):
|
||||
form_fields = form.Fields(INavigationPortlet)
|
||||
label = _(u"Add Folder Navigation Portlet")
|
||||
description = _(u"This portlet display folder navigation elements.")
|
||||
|
||||
def create(self, data):
|
||||
return Assignment()
|
||||
|
||||
|
||||
class EditForm(base.EditForm):
|
||||
form_fields = form.Fields(INavigationPortlet)
|
||||
label = _(u"Edit Folder Navigation Portlet")
|
||||
description = _(u"This portlet display folder navigation elements.")
|
|
@ -0,0 +1,16 @@
|
|||
<?xml version="1.0"?>
|
||||
<portlets
|
||||
xmlns:i18n="http://xml.zope.org/namespaces/i18n"
|
||||
i18n:domain="plone">
|
||||
|
||||
<!-- Portlet type registrations -->
|
||||
|
||||
<portlet
|
||||
addview="pfwbged.folder.portlet.Navigation"
|
||||
title="Classifying Folder Navigation portlet"
|
||||
description="A portlet to display the folder navigation"
|
||||
i18n:attributes="title;
|
||||
description"
|
||||
/>
|
||||
|
||||
</portlets>
|
Reference in New Issue