ok, i need to write an upgrade step....

but what do you think about fixing zope.formlib like so?

i'm not sure which side effects this patch could possibly have, but if
the problem of schema upgrade applies to all zope.formlib based forms,
than it would make sense - IMO.

(btw. i'm using plone 4.0.3 and zope.formlib 3.7.0)

>From bcf7e2b7cb94b145cd502ad57e1363f2e6b4a879 Mon Sep 17 00:00:00 2001
From: Johannes Raggam <[email protected]>
Date: Tue, 15 Feb 2011 12:38:50 +0100
Subject: [PATCH] after schema upgrades (e.g. for plone.app.portlets),
the edit screen cannot be rendered because there is no v
alue for the new field attribute. in this case, use the default value.

---
 zope/formlib/form.py |    6 +++++-
 1 files changed, 5 insertions(+), 1 deletions(-)

diff --git a/zope/formlib/form.py b/zope/formlib/form.py
index 5df88cf..0d3ade3 100755
--- a/zope/formlib/form.py
+++ b/zope/formlib/form.py
@@ -405,7 +405,11 @@ def setUpEditWidgets(form_fields, form_prefix,
context, request,
 
         if ignore_request or readonly or not widget.hasInput():
             # Get the value to render
-            value = field.get(adapter)
+            try:
+                value = field.get(adapter)
+            except AttributeError:
+                # value not available after schema upgrade
+                value = field.default
             widget.setRenderedValue(value)
 
         widgets.append((not readonly, widget))
-- 
1.7.1


On Tue, 2011-02-15 at 11:22 +0100, Johannes Raggam wrote:
> hey all,
> 
> how can i add a new schema field to an already registered portlet?
> 
> when i want to visit the edit form of the portlet, i get an error,
> saying that the new attribute does not exist. for me, it seems that this
> is a but somewhere between plone.app.portlets and zope.formlib.
> 
> 
> 
> 2011-02-14 23:11:55 ERROR Zope.SiteErrorLog 1297721515.110.63984381121
> http://localhost:8880/info/uber-uns/geschichte/++contextportlets
> ++plone.rightcolumn/show-galleries-portlet/edit
> Traceback (innermost last):
>   Module ZPublisher.Publish, line 127, in publish
>   Module ZPublisher.mapply, line 77, in mapply
>   Module ZPublisher.Publish, line 47, in call_object
>   Module plone.app.portlets.browser.formhelper, line 123, in __call__
>   Module zope.formlib.form, line 782, in __call__
>   Module five.formlib.formbase, line 50, in update
>   Module zope.formlib.form, line 745, in update
>   Module zope.formlib.form, line 820, in setUpWidgets
>   Module zope.formlib.form, line 408, in setUpEditWidgets
>   Module zope.schema._bootstrapfields, line 173, in get
> AttributeError: image_size
> 
> 

-- 
johannes raggam / thet
python plone zope development
http://johannes.raggam.co.at/
mailto:[email protected]
http://bluedynamics.com/

_______________________________________________
Product-Developers mailing list
[email protected]
https://lists.plone.org/mailman/listinfo/product-developers

Reply via email to