[Twisted-web] Freeform/formless doesn't work with deferred properties?

Gavrie Philipson twisted-web@twistedmatrix.com
Wed, 24 Dec 2003 11:22:45 +0200


This is a multi-part message in MIME format.
--------------040104010604050804020106
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit

Gavrie Philipson wrote:
> Donovan Preston wrote:
> 
>>
>> On Dec 22, 2003, at 10:38 AM, Gavrie Philipson wrote:
>>
>>> Hi,
>>>
>>> I'm using freeform/formless to handle a form.
>>> However, when the property returns a deferred value, it is not 
>>> handled correctly by freeform.
>>> Is this a bug?
>>>
> ...
> 
>> Your suspicions about the freeform problem being related to the 
>> attribute problem are correct; apparently nevow doesn't deal with 
>> deferreds in attribute values properly. Are you sure you are using CVS 
>> HEAD? I checked in some changes fairly recently which may affect the 
>> situation.
>>
>> Anyway, it's something that should certainly be fixed. In the 
>> meantime, it's good that you have a workaround.

Never mind my previous message.

The attached patch solves the problem with freeform not dealing with 
deferreds in attribute value.

-- Gavrie.

--------------040104010604050804020106
Content-Type: text/x-patch;
 name="freeform-deferred.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="freeform-deferred.patch"

Index: freeform.py
===================================================================
RCS file: /cvs/Quotient/nevow/freeform.py,v
retrieving revision 1.84
diff -u -r1.84 freeform.py
--- freeform.py 23 Dec 2003 19:01:14 -0000      1.84
+++ freeform.py 24 Dec 2003 09:15:42 -0000
@@ -196,6 +196,15 @@

         defaults = IFormDefaults(request)
         value = defaults.getDefault(context.key, context)
+
+        if isinstance(value, Deferred):
+            value.addCallback(self._cb_call, context, data)
+            return value
+        else:
+            return self._cb_call(value, context, data)
+
+    def _cb_call(self, value, context, data):
+        request = context.locate(iwoven.IRequest)
         try:
             _, fbn = calculateFullBindingName(context, context.locate(formless.IBinding))
         except KeyError:

--------------040104010604050804020106--