I encountered a problem when I'm migrating from 2.0 to 2.1, that is,
the TG2.1 can't handle form value of CheckBox correctly.  For example,
following simple controller reproduces this bug:

# -*- coding: utf-8 -*-
"""Sample controller module"""

# project specific imports
from testtg20.lib.base import BaseController
#from testtg20.model import DBSession, metadata

# turbogears imports
from tg import expose, tmpl_context, validate
#from tg import redirect, validate, flash

# third party imports
from pylons.i18n import ugettext as _, lazy_ugettext as l_
#from repoze.what import predicates
from tw.core import WidgetsList
from tw.forms import TableForm, CheckBox
from tw.forms.validators import Bool

class SiteForm(TableForm):
    method = 'POST'
    submit_text = l_('Modify')
    action = 'modify'
    fields = [
        CheckBox('public',
            label_text=l_(u'Public'),
            validator=Bool()
        )
    ]

siteForm = SiteForm()

class SampleController(BaseController):
    #Uncomment this line if your controller requires an authenticated
user
    #allow_only = authorize.not_anonymous()

    @expose('testtg20.templates.sample_form')
    def form(self):
        tmpl_context.form = siteForm
        return dict(page='index')

    @validate(siteForm, error_handler=form)
    @expose()
    def modify(self, public):
        print '#'*10, public
        return str(public)

If you didn't check the CheckBox in the form, then the value "public"
won't be there in arguments, I have no idea how it happened, but TG2.0
did it correctly, but TG2.1 will redirect you to 404 error page, it
seems caused by the missing argument.  To workaround this bug,  we can
modify the modify method

    @validate(siteForm, error_handler=form)
    @expose()
    def modify(self, public=None):
        print '#'*10, public
        return str(public)

Once the CheckBox argument becomes an optional one, TG2.1 can handle
it correctly.  I'm not sure is this a feature or a bug, therefore I
post here.  Hope this could be helpful for people who are migrating
from 2.0 to 2.1

Victor Lin.

-- 
You received this message because you are subscribed to the Google Groups 
"TurboGears" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/turbogears?hl=en.

Reply via email to