2013-07-19 20:49:51 +02:00
|
|
|
from AccessControl import getSecurityManager
|
2013-07-11 22:41:14 +02:00
|
|
|
from zope.interface import implements
|
|
|
|
from five import grok
|
2013-07-19 20:49:51 +02:00
|
|
|
from zope import component
|
2013-11-27 11:36:43 +01:00
|
|
|
from zope import schema
|
2013-12-30 14:50:51 +01:00
|
|
|
from zope.interface import Interface
|
2013-07-11 22:41:14 +02:00
|
|
|
|
2013-07-12 09:13:00 +02:00
|
|
|
from zc.relation.interfaces import ICatalog
|
|
|
|
from zope.app.intid.interfaces import IIntIds
|
|
|
|
|
2013-07-11 22:41:14 +02:00
|
|
|
from plone.dexterity.content import Container
|
2013-12-27 12:15:47 +01:00
|
|
|
from plone.uuid.interfaces import IUUID
|
2013-07-11 22:41:14 +02:00
|
|
|
|
2013-07-12 09:13:00 +02:00
|
|
|
from Acquisition import aq_parent
|
|
|
|
|
2013-07-11 22:41:14 +02:00
|
|
|
from plone.supermodel import model
|
2013-07-16 23:44:07 +02:00
|
|
|
from plone.app.layout.viewlets.interfaces import IBelowContentBody
|
|
|
|
import plone.app.contenttypes.interfaces
|
|
|
|
from plone.dexterity.interfaces import IDexterityContainer
|
2013-07-20 14:46:01 +02:00
|
|
|
from plone.app.contentlisting.interfaces import IContentListingObject
|
2013-07-16 23:44:07 +02:00
|
|
|
|
2013-11-29 12:09:21 +01:00
|
|
|
from plone import api
|
|
|
|
|
2013-11-27 16:40:31 +01:00
|
|
|
from plone.dexterity.browser.view import DefaultView
|
|
|
|
|
2013-11-27 11:36:43 +01:00
|
|
|
from collective.z3cform.rolefield.field import LocalRolesToPrincipals
|
|
|
|
from collective.dms.basecontent.widget import AjaxChosenMultiFieldWidget
|
|
|
|
from plone.autoform import directives as form
|
|
|
|
|
2013-11-29 12:09:21 +01:00
|
|
|
from zope.app.intid.interfaces import IIntIds
|
|
|
|
from z3c.relationfield import RelationValue
|
|
|
|
from zope.lifecycleevent.interfaces import IObjectAddedEvent
|
|
|
|
|
2013-12-30 14:50:51 +01:00
|
|
|
import z3c.table.column
|
|
|
|
|
|
|
|
|
2013-11-29 12:09:21 +01:00
|
|
|
|
2013-07-16 23:44:07 +02:00
|
|
|
from pfwbged.collection.searchview import ResultsTable
|
2013-11-27 11:36:43 +01:00
|
|
|
from collective.dms.thesaurus.keywordsfield import ThesaurusKeywords
|
|
|
|
|
2013-11-29 12:09:21 +01:00
|
|
|
from collective.dms.basecontent.dmsdocument import IDmsDocument
|
|
|
|
|
2013-07-11 22:41:14 +02:00
|
|
|
|
2013-07-19 20:49:51 +02:00
|
|
|
from .link import ILink
|
2013-07-11 22:41:14 +02:00
|
|
|
|
2013-11-27 11:36:43 +01:00
|
|
|
from . import _
|
|
|
|
|
2013-07-11 22:41:14 +02:00
|
|
|
class IFolder(model.Schema):
|
|
|
|
""" """
|
2013-11-27 11:36:43 +01:00
|
|
|
treating_groups = LocalRolesToPrincipals(
|
2014-02-05 09:22:37 +01:00
|
|
|
title=_(u"Can edit"),
|
2013-11-27 11:36:43 +01:00
|
|
|
required=False,
|
|
|
|
roles_to_assign=('Editor',),
|
|
|
|
value_type=schema.Choice(vocabulary=u'collective.dms.basecontent.treating_groups',)
|
|
|
|
)
|
|
|
|
form.widget(treating_groups=AjaxChosenMultiFieldWidget)
|
|
|
|
|
|
|
|
recipient_groups = LocalRolesToPrincipals(
|
2014-02-05 09:22:37 +01:00
|
|
|
title=_(u"Can view"),
|
2013-11-27 11:36:43 +01:00
|
|
|
required=False,
|
|
|
|
roles_to_assign=('Reader',),
|
|
|
|
value_type=schema.Choice(vocabulary=u'collective.dms.basecontent.recipient_groups')
|
|
|
|
)
|
|
|
|
form.widget(recipient_groups=AjaxChosenMultiFieldWidget)
|
|
|
|
|
|
|
|
keywords = ThesaurusKeywords(title=_(u'Keywords'), required=False)
|
2013-07-11 22:41:14 +02:00
|
|
|
|
|
|
|
|
|
|
|
class Folder(Container):
|
|
|
|
""" """
|
|
|
|
implements(IFolder)
|
2013-07-12 09:13:00 +02:00
|
|
|
|
2013-12-02 15:06:07 +01:00
|
|
|
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 = []
|
2013-12-27 12:15:47 +01:00
|
|
|
uuids = []
|
2013-12-02 15:06:07 +01:00
|
|
|
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):
|
2013-12-27 12:15:47 +01:00
|
|
|
uuids.append(IUUID(document))
|
2013-12-02 15:06:07 +01:00
|
|
|
|
2013-12-27 12:15:47 +01:00
|
|
|
portal_catalog = api.portal.get_tool('portal_catalog')
|
|
|
|
children = portal_catalog.searchResults({'UID': uuids})
|
|
|
|
|
|
|
|
return [IContentListingObject(x) for x in children]
|
2013-12-02 15:06:07 +01:00
|
|
|
|
2014-01-22 12:03:29 +01:00
|
|
|
def intid(self):
|
|
|
|
intids = component.getUtility(IIntIds)
|
|
|
|
try:
|
|
|
|
return intids.getId(self)
|
|
|
|
except KeyError:
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
2013-07-12 09:13:00 +02:00
|
|
|
grok.templatedir('templates')
|
|
|
|
grok.context(IDexterityContainer)
|
|
|
|
|
|
|
|
|
2013-12-30 14:50:51 +01:00
|
|
|
class ItemsTable(ResultsTable):
|
|
|
|
def setUpColumns(self):
|
|
|
|
columns = super(ItemsTable, self).setUpColumns()
|
|
|
|
# do not include the delete column, from classifying folders we only
|
|
|
|
# provide an icon for unlink
|
|
|
|
columns = [x for x in columns if x.__name__ != 'dms.delete']
|
|
|
|
return columns
|
|
|
|
|
|
|
|
|
|
|
|
from collective.dms.basecontent.browser import column
|
|
|
|
|
|
|
|
class UnfileColumn(column.IconColumn, column.LinkColumn):
|
|
|
|
grok.name('pfwbged.folder.unfile')
|
|
|
|
grok.adapts(Interface, Interface, ItemsTable)
|
|
|
|
|
|
|
|
header = u''
|
|
|
|
iconName = "++resource++unlink_icon.png"
|
|
|
|
linkContent = _('Unfile')
|
|
|
|
|
|
|
|
def getLinkURL(self, item):
|
|
|
|
for id, child in item.getObject().contentItems():
|
|
|
|
if not ILink.providedBy(child):
|
|
|
|
continue
|
|
|
|
if child.folder.to_object == self.context:
|
|
|
|
return item.getURL() + '/' + id + '/delete_confirmation'
|
|
|
|
return '#'
|
|
|
|
|
|
|
|
|
2013-11-27 16:40:31 +01:00
|
|
|
class ClassifiedItems:
|
2013-07-12 09:13:00 +02:00
|
|
|
|
2013-07-16 23:44:07 +02:00
|
|
|
@property
|
|
|
|
def table(self):
|
2013-12-30 14:50:51 +01:00
|
|
|
table = ItemsTable(self.context, self.request)
|
2013-07-16 23:44:07 +02:00
|
|
|
table.values = self.documents()
|
|
|
|
table.update()
|
|
|
|
return table
|
|
|
|
|
2013-07-12 09:13:00 +02:00
|
|
|
def documents(self):
|
2013-07-18 15:31:25 +02:00
|
|
|
if self.context.id == 'documents' and aq_parent(self.context).portal_type == 'Plone Site':
|
|
|
|
# never return anything in the main documents folder
|
|
|
|
return []
|
2013-07-19 20:49:51 +02:00
|
|
|
|
2013-07-12 09:13:00 +02:00
|
|
|
intids = component.getUtility(IIntIds)
|
2013-07-16 23:44:07 +02:00
|
|
|
intid_catalog = component.getUtility(ICatalog)
|
2013-07-16 14:51:39 +02:00
|
|
|
try:
|
|
|
|
intid = intids.getId(self.context)
|
|
|
|
except KeyError:
|
|
|
|
return []
|
2013-07-19 20:49:51 +02:00
|
|
|
|
2013-12-27 12:15:47 +01:00
|
|
|
uuids = []
|
2013-07-19 20:49:51 +02:00
|
|
|
sm = getSecurityManager()
|
|
|
|
for item in intid_catalog.findRelations({
|
|
|
|
'to_id': intid,
|
|
|
|
'from_interfaces_flattened': ILink}):
|
2013-07-12 09:13:00 +02:00
|
|
|
if item.isBroken():
|
|
|
|
continue
|
2013-07-19 20:49:51 +02:00
|
|
|
|
|
|
|
link = item.from_object
|
|
|
|
if not sm.checkPermission('View', link):
|
|
|
|
continue
|
|
|
|
|
|
|
|
document = aq_parent(link)
|
2013-12-27 12:15:47 +01:00
|
|
|
uuids.append(IUUID(document))
|
2013-07-19 20:49:51 +02:00
|
|
|
|
2013-12-27 12:15:47 +01:00
|
|
|
portal_catalog = api.portal.get_tool('portal_catalog')
|
|
|
|
children = portal_catalog.searchResults({'UID': uuids})
|
2013-11-27 16:40:31 +01:00
|
|
|
|
2013-12-27 12:15:47 +01:00
|
|
|
return [IContentListingObject(x) for x in children]
|
2013-11-27 16:40:31 +01:00
|
|
|
|
|
|
|
|
2014-01-22 13:46:41 +01:00
|
|
|
#class FolderViewlet(grok.Viewlet, ClassifiedItems):
|
|
|
|
# grok.context(plone.app.contenttypes.interfaces.IFolder)
|
|
|
|
# grok.template('foldersviewlet')
|
|
|
|
# grok.viewletmanager(IBelowContentBody)
|
|
|
|
# grok.order(15)
|
2013-11-27 16:40:31 +01:00
|
|
|
|
|
|
|
|
|
|
|
class FolderView(DefaultView, ClassifiedItems):
|
|
|
|
pass
|
2013-11-29 12:09:21 +01:00
|
|
|
|
|
|
|
|
2013-12-27 12:38:19 +01:00
|
|
|
@grok.subscribe(IFolder, IObjectAddedEvent)
|
2013-11-29 12:09:21 +01:00
|
|
|
@grok.subscribe(IDmsDocument, IObjectAddedEvent)
|
|
|
|
def move_to_proper_location(context, event):
|
|
|
|
folder = context.getParentNode()
|
2014-02-04 15:09:00 +01:00
|
|
|
if context.portal_type == 'pfwbgedfolder':
|
|
|
|
if folder.id == 'Members' and aq_parent(folder).portal_type == 'Plone Site':
|
|
|
|
# the fodler is already in the right place, good
|
|
|
|
return
|
|
|
|
if folder.id == 'dossiers' and aq_parent(folder).portal_type == 'Plone Site':
|
|
|
|
# the fodler is already in the right place, good
|
|
|
|
return
|
|
|
|
else:
|
|
|
|
if folder.id == 'documents' and aq_parent(folder).portal_type == 'Plone Site':
|
|
|
|
# the document is already in the right place, good
|
|
|
|
return
|
2013-11-29 12:09:21 +01:00
|
|
|
|
|
|
|
# add a link to classifying folder
|
|
|
|
intids = component.getUtility(IIntIds)
|
|
|
|
link = context.invokeFactory('pfwbgedlink', 'pfwbgedlink-0',
|
|
|
|
folder=RelationValue(intids.getId(folder)))
|
|
|
|
|
|
|
|
# then move the document to the general documents folder
|
|
|
|
clipboard = folder.manage_cutObjects([context.id])
|
2014-02-04 15:09:00 +01:00
|
|
|
if context.portal_type == 'pfwbgedfolder':
|
|
|
|
target_folder = api.portal.get().dossiers
|
|
|
|
else:
|
|
|
|
target_folder = api.portal.get().documents
|
|
|
|
result = target_folder.manage_pasteObjects(clipboard)
|
2013-12-27 12:38:19 +01:00
|
|
|
|
|
|
|
# makes sure original object is deleted
|
|
|
|
try:
|
|
|
|
folder.manage_delObjects([context.id])
|
|
|
|
except AttributeError:
|
|
|
|
pass
|
2014-02-04 14:34:35 +01:00
|
|
|
|
2014-02-04 15:09:00 +01:00
|
|
|
new_url = target_folder.absolute_url() + '/' + result[0]['new_id']
|
2014-02-04 14:34:35 +01:00
|
|
|
context.REQUEST.response.redirect(new_url, lock=True)
|