You must have instances here:
User = FieldSet(User)
User.configure()
UserGrid = Grid(User)
UserGrid.configure()
> --
> You received this message because you are subscribed to the Google Groups "FormAlchemy" group.
> 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.
>
>
You can try something like this:
class FieldSet(Base):
def bind(self, model, request=None, **kw):
fs = super(FieldSet self).bind(model, request=request, **kw)
# add field here
return fs
User = FieldSet(User)
A better solution is to create a crsf renderer and override .render()
to get the value from the request.
class CRSF(HiddenFieldRenderer):
def render(self):
return '<input value="%" />" % self.request.session['crsf']
Then something like:
User = FieldSet(User)
User.configure()
User.append(Field('crsf').set(renderer=CRSF))
Why not. But formalchemy use instances for years. That's how it work.
You can also subclass the fieldset to add a csrf field and instanciate it.
>
> 2. I just want to add a hidden field to my form, why should I need to
> define a renderer for this?
>
Because you want to get the value from a session. There is probably
others way to do that but it's the easy one.
> One last question...When I try the code you suggest:
>
> User = FieldSet(User)
> User.configure()
> User.append(Field('crsf').set(renderer=CRSF))
>
> SQLAlchemy gets really unhappy about what I've done with the 'User'
> name. If I change the instance name to UserFieldSet then
> pyramid_formalchemy gets really unhappy. What are the naming
> conventions I should be using? Is this documented somewhere?
>
I guess you need this:
User = FieldSet(models.User)
That's not documented as I can see but you can have a look at the demo:
https://github.com/FormAlchemy/formalchemy_project/blob/master/formalchemy_project/forms.py