78 lines
2.1 KiB
Python
78 lines
2.1 KiB
Python
from AccessControl import getSecurityManager
|
|
from zope.interface import implements
|
|
from five import grok
|
|
from zope import component
|
|
|
|
from zc.relation.interfaces import ICatalog
|
|
from zope.app.intid.interfaces import IIntIds
|
|
|
|
from plone.dexterity.content import Container
|
|
|
|
from Acquisition import aq_parent
|
|
|
|
from plone.supermodel import model
|
|
from plone.app.layout.viewlets.interfaces import IBelowContentBody
|
|
import plone.app.contenttypes.interfaces
|
|
from plone.dexterity.interfaces import IDexterityContainer
|
|
from plone.app.contentlisting.interfaces import IContentListingObject
|
|
|
|
from pfwbged.collection.searchview import ResultsTable
|
|
|
|
from .link import ILink
|
|
|
|
class IFolder(model.Schema):
|
|
""" """
|
|
|
|
|
|
class Folder(Container):
|
|
""" """
|
|
implements(IFolder)
|
|
|
|
grok.templatedir('templates')
|
|
grok.context(IDexterityContainer)
|
|
|
|
|
|
class FolderViewlet(grok.Viewlet):
|
|
grok.context(plone.app.contenttypes.interfaces.IFolder)
|
|
grok.template('foldersviewlet')
|
|
grok.viewletmanager(IBelowContentBody)
|
|
grok.order(15)
|
|
|
|
@property
|
|
def table(self):
|
|
self.context.request = self.request
|
|
table = ResultsTable(self.context, self.request)
|
|
table.values = self.documents()
|
|
table.update()
|
|
del self.context.request
|
|
return table
|
|
|
|
def documents(self):
|
|
if self.context.id == 'documents' and aq_parent(self.context).portal_type == 'Plone Site':
|
|
# never return anything in the main documents folder
|
|
return []
|
|
|
|
intids = component.getUtility(IIntIds)
|
|
intid_catalog = component.getUtility(ICatalog)
|
|
try:
|
|
intid = intids.getId(self.context)
|
|
except KeyError:
|
|
return []
|
|
|
|
documents = []
|
|
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)
|
|
documents.append(IContentListingObject(document))
|
|
|
|
return documents
|