Brainspiritus

Funkenflug aus flammenden Synapsen.

In case I ever need this again, part 437

Medium-complex Plone Python scripts (looking at request), here: iterating over all plone instances and showing pending upgrade steps.

# Import a standard function, and get the HTML request and response objects.
from Products.PythonScripts.standard import html_quote
request = container.REQUEST
response =  request.response

# Return a string identifying this script.
print "<html><body><h1>Mass update steps</h1>"

doit = request.form.get('act',None)
if doit:
    print "<b>Updating now, cross your fingers and hold on to your hats</b>"
    print "<dl>"
    for pth in request.form.keys():
        if not '/' in pth:
            continue # this is the "act" variable?
        print "<dt>%s</dt>" % (pth,)
        plo = container.restrictedTraverse(pth)
        pst = plo.portal_setup
        for profile in request.form[pth]:
            print "<dd>%s ..." % (profile,)
            pst.upgradeProfile(profile)
            print " done</dd>"

    print "</dl>"
    return printed

instances=container.PrincipiaFind(container, 
                      obj_metatypes="Plone Site", search_sub=0)
mountpoints=container.PrincipiaFind(container, obj_metatypes="Folder", search_sub=0)

for (name, folder) in mountpoints:
  instances += folder.PrincipiaFind(folder,obj_metatypes="Plone Site", search_sub=0)

print "<form method='POST'><dl>"
for (name, site) in instances:
    pending = site.portal_setup.listProfilesWithPendingUpgrades()
    if not pending:
        continue
    print """<dt>%s</dt>""" % (name,)
    for step in pending:
        print """<dd><label><input name='%s:list' value="%s" type='checkbox' />%s</label></dd>""" % ('/'.join(site.getPhysicalPath()),step, step,)

print "</dl><input name='act' type='submit' value='Perform Upgrade Steps' /></form>"

return printed