durusmail: quixote-users: form2: troubles from a get
form2: troubles from a get
2004-02-24
2004-03-10
2004-03-10
2004-03-10
2004-03-10
form2: troubles from a get
Daniele Varrazzo
2004-02-24
I am trying to convert a rather complex application to use form2 instead of
form: I think their design can simplify development. I am starting from the
example published in http://mail.mems-exchange.org/pipermail/quixote-
users/2003-October/001998.html.

My app expects a request like http://localhost/esp/xpr/edit?id=247. In xpr.ptl,
the edit method fetches  the record 247 from the database and use its data to
populate the form. But then

    if not form.is_submitted():
        return render()

this render is never executed because globals()['_publisher'].get_request().form
== {'id': '247'}, so form.is_submitted() == 1 :-/

I solved this by defining

    def is_submitted(self):
        """() -> bool

        Return true if a form was submitted.
        """
        r = get_request()
        return r.get_environ('REQUEST_METHOD') == 'POST' and bool(r.form)

in my form subclass, but this wouldn't help if the form were generated by
another form...

Am I wrong? Maybe the tipical usage for form2 is different from the "if not
form.is_submitted(): return render()" pattern shown in that example?

Another question: what is the best way to populate the form before rendering it?
I can read it with a dict protocol, but how should I write control values?

Bye

--
Daniele Varrazzo                                varrazzo@unisi.it
Dipartimento di Biologia Molecolare
Universita' di Siena
Via del Capitano, 15   53100 Siena   (Italy)



reply