69 lines
2.0 KiB
Python
69 lines
2.0 KiB
Python
from zope.interface import implements
|
|
from five import grok
|
|
from zope import schema, component
|
|
from plone.directives import form
|
|
|
|
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 . import _
|
|
|
|
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):
|
|
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 = []
|
|
for item in intid_catalog.findRelations({'to_id': intid}):
|
|
if item.isBroken():
|
|
continue
|
|
document = aq_parent(item.from_object)
|
|
# 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({'UID': uuid}))
|
|
return documents
|