TG 1.1 and forms with nested schemas

5 views
Skip to first unread message

Daniel Haus

unread,
Oct 13, 2009, 7:19:42 AM10/13/09
to TurboGears
Hi there,

here's another problem I encountered when porting my webapp from TG
1.0 to TG
1.1. Given a form with schemas (stripped down excerpt below):

class RegistrationForm(ListForm):
class RegistrationFields(WidgetsList):
class PersonalDetailsFields(WidgetsList):
lastname = TextField(label=_(u"Last name"))
firstname = TextField(label=_(u"First name"))
personal = FieldSet(
legend = _(u"Personal information"),
fields = PersonalDetailsFields())

class RegistrationSchema(Schema):
class PersonalDetailsSchema(Schema):
lastname = UnicodeString(strip=True, not_empty=True,
max=20)
firstname = UnicodeString(strip=True, not_empty=True,
max=20)
personal = PersonalDetailsSchema()

fields = RegistrationFields()
validator = RegistrationSchema()

This worked pretty fine with the validate-decorator in 1.0. Now with
1.1 I
always get validate-errors for the schema named
"PersonalDetailsSchema" as
there is no such sub-form (the only given sub-form is given by the key
'personal'). Actually the real name would be "personal", like the name
of the
form above. The @validate-decorator seems to validate the instance of
the
PersonalDetailsSchema-class as well as the class itself.

If I clear out the schema-class by setting PersonalDetailsSchema=None
after the instantiation of 'personal' like this:

class RegistrationSchema(Schema):
class PersonalDetailsSchema(Schema):
lastname = UnicodeString(strip=True, not_empty=True, max=20)
firstname = UnicodeString(strip=True, not_empty=True, max=20)
personal = PersonalDetailsSchema()
PersonalDetailsSchema = None

validation works well. I can as well move the RegistrationSchema-class
out of the
RegistrationForm-class to module level, which also works. The problem
is that
both ways somehow feel wrong to me. And moreover, I have lots of huge
formsets
in my app, which would require a lot of changes.

What am I missing here? Is this a FormEncode-issue? What's the
"offcial" way
to define forms with nested schemas in TG 1.1?

Thank you!
Daniel

Christopher Arndt

unread,
Oct 13, 2009, 8:06:51 AM10/13/09
to turbo...@googlegroups.com
Daniel Haus schrieb:

> 1.1. Given a form with schemas (stripped down excerpt below):
> This worked pretty fine with the validate-decorator in 1.0. Now with
> 1.1 I always get validate-errors
>
> What am I missing here? Is this a FormEncode-issue? What's the
> "offcial" way
> to define forms with nested schemas in TG 1.1?

It shouldn't have changed. I'm no expert on this, but this might also
have to do with changes introduced in later 1.0.x version. Which version
are you running currently?

To be able to decide if this is a bug, are you able to construct a
minimal example app that demonstrates the problem? That would ease the
job of debugging this for us tremendously.

Cheers, Chris

Daniel Haus

unread,
Oct 13, 2009, 9:39:22 AM10/13/09
to TurboGears
Currently it runs on 1.0.8 (and FormEncode 0.7.1, possibly it has to
do with this?)

I'll try to setup a minimal example.

Thank you, Chris!

Daniel

Daniel Haus

unread,
Oct 13, 2009, 10:44:29 AM10/13/09
to TurboGears
Alright, I just uploaded a minimal example to show what I mean.

The URL is
http://danielhaus.de/files/NestedForms-1.0.tar.gz

Thank you & greetings!
Daniel

On 13 Okt., 14:06, Christopher Arndt <chris.ar...@web.de> wrote:

Christopher Arndt

unread,
Oct 13, 2009, 12:26:12 PM10/13/09
to turbo...@googlegroups.com
Daniel Haus schrieb:

> Alright, I just uploaded a minimal example to show what I mean.
>
> The URL is
> http://danielhaus.de/files/NestedForms-1.0.tar.gz

Thanks for the testcase. I can confirm your problem with TG 1.1 and
FormEncode 1.2. but also with TG 1.0 and FE 1.2.1. If I use FE 0.7.1 the
problem goes away.

I suggest you try out progressive FE versions until your app breaks
again and find out what changed for this version. Using virtualenv makes
this easy

Sorry for not being able to help more, but I never use your way of
defining forms and validators.

If you come up with a solution and you think TurboGears should support
this better, please let us know!


Chris

Christoph Zwerschke

unread,
Oct 13, 2009, 5:11:01 PM10/13/09
to turbo...@googlegroups.com
Christopher Arndt schrieb:

> If you come up with a solution and you think TurboGears should support
> this better, please let us know!

You can also create a trac ticket and attach your example there, so it
will not get lost.

-- Christoph

Daniel Haus

unread,
Oct 14, 2009, 1:29:36 AM10/14/09
to TurboGears
Thank you for your help. The problem is, that I have to use Python 2.6
as I'm not able to get MySQL-python to run with Python 2.5 on Mac OS X
10.6. This means I can't use TG 1.0 and so I have to use FormEncode
1.2. Maybe I should find another way of building my forms (or get the
mysql-connector to work with Python 2.5). Any hints on that?

Daniel Haus

unread,
Oct 14, 2009, 1:43:25 AM10/14/09
to TurboGears
Thank you. I created Ticket #2393.

http://trac.turbogears.org/ticket/2393

Daniel

Christopher Arndt

unread,
Oct 14, 2009, 10:39:55 AM10/14/09
to TurboGears
Daniel Haus schrieb:

> Thank you. I created Ticket #2393.
>
> http://trac.turbogears.org/ticket/2393

I have added a patch with a partial fix to the ticket. Partial in the
sense that you will still have to change your (IMHO broken) nested
validator definitions.

Chris

Daniel Haus

unread,
Oct 15, 2009, 3:09:04 AM10/15/09
to TurboGears
Great, Chris.

In fact, I tried to define my nested validators the way you suggested
in the first place, which didn't work. So I'm glad I can do it now.
I'll give it a shot soon.

Thanks a lot!
Daniel
Reply all
Reply to author
Forward
0 new messages