Re: [formalchemy] Problem with NoSQL-Forms

9 views
Skip to first unread message

Gael Pasgrimaud

unread,
Dec 19, 2012, 6:16:07 PM12/19/12
to forma...@googlegroups.com
Hi,

On 19/12/2012 21:45, M T wrote:
> Hi,
>
> I'm using FormAlchemy in a Pyramid application, there I use it for
> some SQL-Alchemy mapped classes (works fine) and for some forms which
> are not directly related to my database.
>
> So I created a form like this:
>
> class HomeForm(object):
> '''form for the home view'''
> yourname = Field().label(_(u'Your name')).required()
> yourmail = Field().label(_(u'Your email')).validate(validators.email)
>
> and a little helper function like this:
>
> def home_form(data=None):
> '''
> create Form for creating a Pot with one participant
> '''
> home_fs = FieldSet(HomeForm, data=data)
> return home_fs
>
> (okay, at this stage it does not make that much sense... but later on
> you will see, why i use this)
>
> Every time I call this helper function a new instance of this class is
> created (as I expected it), but as the fields are class-variables all
> instances of HomeForm are linked to the same Field instances,
> which leads to weird behaviour, like showing old validation error
> messages (even without validating this instance of HomeForm).
>
> My question is: is this a bug, or a known problem? Or is there an easy
> way to avoid the problem?
>

If you're not afraid by the "zope" word, you should have a look at
http://docs.formalchemy.org/formalchemy/ext/zope.html which is much more
powerful and keep fields order.

> I found a workaround: By defining the class localle in the helper
> function, not only new instances but really new classes (with new
> field instances) are created at each call of my helper function.
> But this definition of a local class seems not to be the "right" way
> to do this.
>
> Thanks,
> Maximilian
>
>
> --
> You received this message because you are subscribed to the Google
> Groups "FormAlchemy" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/formalchemy/-/iCcfr4vrzNYJ.
> To post to this group, send email to forma...@googlegroups.com.
> To unsubscribe from this group, send email to
> formalchemy...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/formalchemy?hl=en.

Maximilian Trescher

unread,
Dec 20, 2012, 4:02:31 AM12/20/12
to forma...@googlegroups.com
Hi,

> If you're not afraid by the "zope" word, you should have a look at
> http://docs.formalchemy.org/formalchemy/ext/zope.html which is much more
> powerful and keep fields order.

Thanks for this hint! I will try this soon.


Maximilian
Reply all
Reply to author
Forward
0 new messages