python - How to get fields displaying in a custom plone dexterity form? -
i'm trying avoid writing out few hundred fields in custom addform plone dexterity object.
i've created loop called customvisitformtemplate.pt
def otherfields2(self): #print "this gets called3" customs="" fields = field.fields(isitevisit) #print dir(fields) r in fields: #print dir(r) #print r.title() if r.startswith("current") or r.startswith("landcover") or r.startswith("surrounding"): pass else: print 'in others', r customs=customs+"""<tal:field tal:replace='structure view/widgets/%s/@@ploneform-render-widget'/>""" % (r) print customs return customs
in custom template call this:
<fieldset> <legend>general info</legend> <span tal:define="otherfields view/otherfields2"> <div tal:content="structure otherfields" /> </span> </fieldset>
however, on execution tal statement not call widget, , outputs html:
<tal:field tal:replace="view/widgets/siteid/@@ploneform-render-widget" />
if use following code directly in custom temlpate:
<tal:field tal:replace="view/widgets/siteid/@@ploneform-render-widget" />
it outputs html , works:
<div id="formfield-form-widgets-sitevisitnotes" class="field z3cforminlinevalidation kssattr-fieldname-form.widgets.sitevisitnotes"> <label class="horizontal" for="form-widgets-sitevisitnotes"> site visit notes </label> <div class="fielderrorbox"></div> <textarea id="form-widgets-sitevisitnotes" class="textarea-widget text-field" name="form.widgets.sitevisitnotes"></textarea> </div>
how looped code .py file output same "direct" code?
thanks suggestions
after quite playing around, got complexity working :).
<fieldset> <legend>general info</legend> <div> <metal:define define-macro="widget_rendering"> <!-- not sure if define-macro needed --> <span tal:define="widgets view/widgets/values"> <tal:widgets repeat="widget python:[w w in widgets if not w.name.startswith('form.widgets.current') , not w.name.startswith('form.widgets.surrounding') , not w.name.startswith('form.widgets.landcover')]"> <metal:field-slot define-slot="field"> <metal:field define-macro="field"> <tal:widget tal:condition="python:widget.id !='form-widgets-url'" tal:replace="structure widget/@@ploneform-render-widget"/> </metal:field> </metal:field-slot> <!--</span>--> </tal:widgets> </span> </metal:define> <br> <!-- keep label , input field --> </div> </fieldset>
here still issue in terms of having title , input box stay when resizing page, sorting code works.
Comments
Post a Comment