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

Gavrie Philipson twisted-web@twistedmatrix.com
Mon, 22 Dec 2003 17:38:14 +0200


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

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?

Attached is an example (based on DP's examples) that shows the behavior: 
When rendering the page, instead of seeing "50" in the input field, it 
shows something like '<Deferred at 0xbec7c30c>'.

PS: A similar thing happens when returning a deferred as an attribute of 
context.tag in a render method.

-- Gavrie.

--------------030001020902000004080608
Content-Type: text/plain;
 name="formpost-defer.tac"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="formpost-defer.tac"


from twisted.application import service, internet
from twisted.internet import defer

from nevow import appserver
from nevow import renderer
from nevow import tags
from nevow import formless
from nevow import freeform


class IMyForm(formless.TypedInterface):
    foo = formless.Integer()


class FormPage(renderer.Renderer):
    __implements__ = IMyForm,

    def _getter(self):
        d = defer.Deferred()
        d.callback(50)
        return d

    foo = property(_getter)

    document = tags.html[
    tags.body[
        "Hello! Here is a form:",
        freeform.configure
    ]
]


application = service.Application("nestedmenus")
internet.TCPServer(
    8080, 
    appserver.NevowSite(
        FormPage()
    )
).setServiceParent(application)

--------------030001020902000004080608--