Daniel Holth writes:

> On Sep 15, 5:53 pm, Martin Aspeli wrote:
>> Daniel Holth wrote:
>> > Another plone.z3cform problem -- I am having trouble finding the
>> > minimum template that will "just work" if I setup
>>
>> > index = ViewTemplateForm('something.pt')
>>
>> You shouldn't need to specify a template to have it "just work"; the
>> default layout template should work (at least if you have
>> plone.app.z3cform installed, which provides the Plone default look and
>> feel template).
>
> http://paste.plone.org/23853 is my code. It is working now but I did
> not know how to do everything I wanted to do.
>
> It does "just work", but when I try to set my FormWrapper's index = to
> the things I've tried (all variations on ViewPageTemplateFile('a-
> template-included-in-plone.z3cform.pt') the form does not render,
> complaining about missing attributes in my FormWrapper. Reading
> farther in plone.z3cform's source code, it looks like I might just
> create an adapter ZopeTwoFormTemplateFactory(path,
> form=IMyFormWrapper), have my form wrapper implement that interface,
> and register the adapter in zcml, and then I will have a customizable
> template that "just works". Not sure.

When setting the index to a ViewPageTemplateFile, make sure you use the
variant from Products.Five.  Are you doing that?

layout.pt is the template that you want to start with.  The comments in
plone.z3cform.layout should give you a good idea on how to hook into the
FormWrapper.

>> > I've tried the templates from plone.z3cform to no avail. All I really
>> > want to do is to add a class to the <body> tag, which I can do
>> > (messily?) in FormWrapper.__call__ by setting template.id = "some-
>> > string".
>>
>> Look at the standard templates then. They have macros you can re-use.
>
> I repeatedly feel like I am missing some great tutorial on how to ask
> the component registry which component is registered for what. I did
> eventually find that layout.pt is the default template for these forms
> but I did not notice that when stepping through and inspecting
> layout.py's FormWrapper.__call__ "template" variable in the debugger.

I think the template should have a 'filename' attribute or some such
that should help you find out where it's coming from.

I'm using lots of these wrappers that just use a hardwired layout
template in S&D like so:

  StatsView = plone.z3cform.layout.wrap_form(
      StatsForm,
      index=ViewPageTemplateFile('controlpanel.pt'),
      label = _(u"Newsletter statistics"),
      back_link = controlpanel.back_to_controlpanel)

Where ViewPageTemplateFile comes from from
'Products.Five.browser.pagetemplatefile'.  This uses a local
'controlpanel.pt' instead of the standard layout, without relying on any
lookup (which definitely complicate the story).

Looking at plone.z3cform.layout, you'll see this:

  index = None # override with a page template, or rely on an adapter

The keyword args to 'plone.z3cform.layout.wrap_form' correspond to the
attributes of that class.  I understand that in your case you need to
subclass so you can override __call__ (or provide a 'index' method) to
"own" the response.

>> > The other things I have not yet figured out include how to replace the
>> > default "Yes/No" for a Bool() field with a checkbox widget, and how to
>> > have widgets that provide instructions between fields without asking
>> > for any input. Any advice?
>>
>> There's a widget for this in z3c.form, I think; you just need to set a
>> custom widgetFactory. For more detailed control over text and layout,
>> you'll need a custom template. That really should work like z3c.form so
>> look at its docs.
>
> I wasn't sure where to manipulate a manager =
> field.Fields(ISomething) ... just in the top level of my .py file
> defining the form's interface? Or where to manipulate a manager =
> field.FieldWidgets(personForm, request, srichter), which are different
> kinds of managers? In the z3c.form documentation, the user
> calls .render() from the prompt, but in plone.z3cform the framework
> renders the form, so it was not clear to me how to transfer that
> documentation to my work.
>
> For me, the z3c.form documentation would benefit greatly from a "here
> is the complete source code to do x" listing, after running through
> the doctest snippet / commmentary sequences. I had trouble
> understanding how the parts are supposed to combine together to create
> a working whole.

I'm sure the z3c.form guys would appreciate your input.  The
z3c.formdemo package might also be interesting to look at.  (Although it
doesn't work with Plone yet.)


-- 
http://danielnouri.org


_______________________________________________
Product-Developers mailing list
[email protected]
http://lists.plone.org/mailman/listinfo/product-developers

Reply via email to