On Aug 30, 12:36 pm, Ben Sizer <[email protected]> wrote: > On Aug 30, 2:42 pm, Benjamin Sims <[email protected]> wrote: > > The demo site provides nice examples of its capabilities: > > >http://deformdemo.repoze.org/ > > Having explored this a little more, I must admit I find it daunting. > Sure, for simple stuff it's "easier than building HTML by hand", but > for anything non-trivial, it's hard to work out what to do, because > everything's hidden from me. > > I have an object which is a few string fields and then a list of > references to Tag objects. The input for the rest of the object is > fine but I can't see any way to handle the tags, because the way the > schema seems to work is that it assumes the object is composed of > everything within it, as opposed to associating with things outside of > it. So I can add new tags to the object, but that is not the behaviour > I want, because the user needs to be limited to existing tags.
What you want is to use the deferred decorator and then pass your values along using .bind() http://deformdemo.repoze.org/deferred_schema_bindings/ Something like this using def deferred_csrf_token(node, kw): csrf_token = kw.get('csrf_token') return csrf_token class UserSchema(colander.Schema): csrf_token = colander.SchemaNode( colander.String(), widget = deform.widget.HiddenWidget(), default = deferred_csrf_token, ) name = colander.SchemaNode( colander.String(), widget = deform.widget.TextInputWidget(size=80), missing=u'', ) phone = colander.SchemaNode( colander.String(), widget = deform.widget.TextInputWidget(size=80), missing=u'', ) @view_config(route_name='profile_index', renderer='profile_index.jinja2', permission='authenticated') def index(request): schema = UserSchema().bind(csrf_token=request.session.get_csrf_token()) form = deform.Form(schema, buttons=('Update Profile',)) return {'form':form.render()} something closer to what you might want: @colander.deferred def deferred_users_widget(node, kw): users = kw.get('user_list', []) return deform.widget.SelectWidget(values=users) class FormSchema(colander.Schema): label = colander.SchemaNode(colander.String(), title='or', missing=u'', widget = LabelWidget(), ) user_id = colander.SchemaNode(colander.String(), title='Username', widget = deferred_users_widget, ) In your view: schema = HtaccessSchema().bind(user_list=get_ftpusers(self.uid)) form = deform.Form(schema, buttons=('Update',)) -- You received this message because you are subscribed to the Google Groups "pylons-discuss" 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/pylons-discuss?hl=en.
