Question

In Plone, the ModificationDate and effective date of container objects really returns the last time the container was modified, but doesn't keep track of the contained object's modification times.

I'm wondering if there is a better way, or even some simple built-in way alternative to this awkward and potentially very slow query to determine the date that a container's contents were modified - or in this case below - the last time something was 'added'.

def getFolderModificationDate(folderBrain, catalog):
    """Returns last time content was modified inside a folder"""

    brains = catalog.search(query_request={ "path": folderBrain.getPath(),
                                            "portal_type": 'Article',
                                            'review_state':'published'},
                            sort_index = 'effective',
                            reverse=1,
                            limit=1)

    if brains:
        return brains[0].ModificationDate
    else:
        #return the folder's modificationDate
        return folderBrain.ModificationDate

This date will be used downstream in a non-plone application as a hash value for caching the folder's contents.

Was it helpful?

Solution

Nope, that's exactly how I'd do it.

The alternative would be to use an event to update the modification date of parent folders, but that'd incur a the risk of conflict errors.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top