This repository has been archived on 2023-02-21. You can view files and clone it, but cannot push or open issues or pull requests.
pfwbged.folder/src/pfwbged/folder/folder.py

84 lines
2.4 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 import api
from plone.uuid.interfaces import IUUID
from plone.app.layout.viewlets.interfaces import IBelowContentBody
import plone.app.contenttypes.interfaces
from plone.dexterity.interfaces import IDexterityContainer
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)
portal_catalog = api.portal.get_tool('portal_catalog')
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(document)
# this is stupid, getting back to the brain, but the rest of the
# stuff expects a brain, not an actual object.
uuid = IUUID(document, None)
documents.extend(portal_catalog.unrestrictedSearchResults({'UID': uuid}))
return documents