Ticket #20219 (new Bug)

Opened 16 months ago

Last modified 15 months ago

can't edit existing collection-portlets after upgrade to plone.portlet.collection 2.1.6

Reported by: pbauer Owned by: davisagli
Priority: minor Milestone: 4.x
Component: Upgrade/Migration Version: 4.3
Keywords: Cc: pbauer

Description

plone.portlet.collection 2.1.6 (included in Plone 4.3.4) introduced a new field 'exclude_context' that prevents portlets created with earlier versions to be edited.

Traceback (innermost last):
  Module ZPublisher.Publish, line 138, in publish
  Module ZPublisher.mapply, line 77, in mapply
  Module ZPublisher.Publish, line 48, in call_object
  Module plone.app.portlets.browser.formhelper, line 126, in __call__
  Module zope.formlib.form, line 795, in __call__
  Module five.formlib.formbase, line 50, in update
  Module zope.formlib.form, line 758, in update
  Module zope.formlib.form, line 833, in setUpWidgets
  Module zope.formlib.form, line 412, in setUpEditWidgets
  Module zope.schema._bootstrapfields, line 215, in get
AttributeError: exclude_context 

Change History

comment:1 Changed 15 months ago by trs22

I ran into the same issue on a site upgraded from 4.1.6 to 4.3.4.1. Maybe this could be an upgrade step, since it's not throwing an error from within the plone.portlet.collection product?

For what it's worth, my fix (run from the debug prompt) was:

from Products.CMFCore.utils import getToolByName
from Testing.makerequest import makerequest
from agsci.subsite.events import getPortletAssignmentMapping
from plone.portlet.collection.collection import Assignment as ppcca
from plone.portlets.interfaces import IPortletAssignmentMapping, IPortletManager
from zope.component import ComponentLookupError, getMultiAdapter, getUtility
from zope.component.hooks import setSite
import transaction

def getPortletAssignmentMapping(context, name):
    portlet_manager = getUtility(IPortletManager, name=name, context=context)
    return getMultiAdapter((context, portlet_manager), \
                            IPortletAssignmentMapping, context=context)

# List of portlet manager names
managers = """
plone.rightcolumn
plone.leftcolumn
""".strip().split()

# Change to False to make and commit changes
dry_run = True

# Boilerplate when running through debug
app = makerequest(app)
app._p_jar.sync()

# Path to Plone site
site = app['Plone']

# Set current site
setSite(site)

# Grab catalog tool
portal_catalog = getToolByName(site, "portal_catalog")

# Iterate through all items in catalog
for r in portal_catalog.searchResults():
    try:
        # Get the Plone object from the brain
        o = r.getObject()
    except (KeyError, AttributeError):
        continue
    else:
        # Iterate through managers
        for m in managers:
            try:
                # Get portlets for manager
                pm = getPortletAssignmentMapping(o, m)
            except ComponentLookupError:
                continue
            else:
                # Iterate through portlets
                for k in pm.keys():
                    # Portlet object
                    p = pm[k]
                    # If we're a collection portlet
                    if isinstance(p, ppcca):
                        # ... and we don't have exclude_context
                        if not hasattr(p, 'exclude_context'):
                            print "Fix %s on %s (%s)" % (k, r.getURL(), m)
                            # Do it live?
                            if not dry_run:
                                # Add attribute with default setting
                                p.exclude_context = True
                                transaction.commit()
Note: See TracTickets for help on using tickets.