Cancel the default sort order of Plone in the_contents folder

How can I make my papal custom type display its list of objects in reverse chronological order in the folder_contents view?

By default, the oldest object is at the top of the list, I would like the new object to just be added to the top of the list.

It would be nice if Plone had this function out of the box ... if that fails, I can't find it.

+4
source share
5 answers

To actually change the obj position in your parent, you can use Zope2 OFS.IOrderedContainer-interface to access the appropriate methods and connect it to zope.lifecycleevent.interfaces.IObjectAddedEvent, as in this Plone-addon " adi.revertorder " (disclaimer: author = meh):

In the list, configure.zcmlregister an eventlistener:

<subscriber for="Products.CMFCore.interfaces.IContentish
                 zope.lifecycleevent.interfaces.IObjectAddedEvent"
            handler=".subscriber.revertOrder" />

And in the handler (here:) subscriber.pydefine the called method:

from Acquisition import aq_inner
from Acquisition import aq_parent

from OFS.interfaces import IOrderedContainer

def revertOrder(obj, eve):
    """
    Use IOrderedContainer interface to move an object to top of folder on creation.
    """
    parent = obj.aq_inner.aq_parent
    ordered = IOrderedContainer(parent, None)
    if ordered is not None:
        ordered.moveObjectToPosition(obj.getId(), 0)

Refers to a content type based on Dexterity and Archetype.

See also docs: http://docs.plone.org/external/plone.app.dexterity/docs/advanced/event-handlers.html

+9
source

_contents View ( ) , . , drag'n'drop.

plone append, . .

, , _contents, , folder_contents , , ( ) manual sort column.

folder_contents

tableview.py of plone.app.content → https://github.com/plone/plone.app.content/blob/2.1.5/plone/app/content/browser/tableview.py#L30

+3

.

.

script ( 'Python Script'), moveToFirstPosition ' :

contentObject = review_state.object
obj_id = contentObject.getId()
parent = contentObject.aq_parent
parent.moveObjectToPosition(obj_id, 0)

"moveToTop" script, moveToFirstPosition '

, . .

+2

collective.sortmyfolder , . , , . , , .

+1

Thanks to everyone. The pointer from Ida got me there ... and I only need to import IObjectAddedEvent:

In myobject.py

from zope.lifecycleevent.interfaces import IObjectAddedEvent

...

class IMyObject(model.Schema):

...

# Listener for adding myObject: move myObject to the top of the parent folder
def addItemToTop(myObject, event):
    event.newParent.moveObjectToPosition(myObject.getId(),0)

And register the listener in the configure.zcml file:

<subscriber
    for=".myobject.IMyObject zope.lifecycleevent.interfaces.IObjectAddedEvent"
    handler=".myobject.addItemToTop"
/>

Doco is here: http://docs.plone.org/external/plone.app.dexterity/docs/advanced/event-handlers.html

+1
source

Source: https://habr.com/ru/post/1608621/


All Articles