durusmail: quixote-users: new snapshot release
new snapshot release
2003-10-08
2003-10-09
new snapshot release
Neil Schemenauer
2003-10-08
There's a new Quixote snapshot available at:

  http://www.mems-exchange.org/software/files/quixote/Quixote-20031008.tar.gz

Those of you on the quixote-checkins list might have noticed the
"next generation form framework" checkin.  That's the new toy in
this snapshot and we would appreciate feedback on it.  We hope to
one day replace the existing 'form' package with the new one
(currently called form2).

We think the new framework is considerably less magical than the old
one and more flexible to boot.  The major change is that, if the
form is submitted, widgets parse themselves when initialized.  That
simplifies a lot of other things.

The documentation is not finished but I attached a small example
form.

  Neil


#########################################################################

from <...> import get_user
from <...> import header, footer
from quixote import htmltext
from quixote.form2 import Form, StringWidget, PasswordWidget

def login_form(request):
    form = Form(use_tokens=False)
    form.add(StringWidget, 'user_id', title='User ID')
    form.add(PasswordWidget, 'password', title='Password')
    form.add_submit('login', 'Login')

    def render [html] ():
        header()
        form.render()
        footer()

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

    user_id = form['user_id']
    password = form['password']
    if not user_id:
        form.set_error('user_id', "You must supply a user ID")
    user = get_user(user_id)
    if user_id and not user:
        form.set_error('user_id', "Invalid user ID")
    if user and not password:
        send_new_password(user)
        form.set_error('password',
                       "A new password has been generated and "
                       "e-mailed to your address.")
    if user and password and not user.valid_password(password):
        form.set_error('password', "Incorrect password")

    if form.has_errors():
        return render()

    request.session.set_user(user)
    return htmltext(request.redirect("/"))

def send_new_password(user):
    ...


reply