我试图避免在我的自定义addform中为plone dexterity对象写出几百个字段。
我创建了一个从我的customVisitFormTemplate.pt
调用的循环 def otherFields2(self):
#print "this gets called3"
customs=""
fields = field.Fields(ISiteVisit)
#print dir(fields)
for 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
在自定义模板中我用它来调用它:
<fieldset>
<legend>General Info</legend>
<span tal:define="otherFields view/otherFields2">
<div tal:content="structure otherFields" />
</span>
</fieldset>
然而,在执行时,tal语句不会调用窗口小部件,而是输出到html:
<tal:field tal:replace="view/widgets/siteID/@@ploneform-render-widget" />
如果我直接在我的自定义temlpate中使用以下代码:
<tal:field tal:replace="view/widgets/siteID/@@ploneform-render-widget" />
它输出到html并且它可以工作:
<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>
如何从我的.py文件中获取循环代码以输出与“直接”代码相同的代码?
感谢任何建议
答案 0 :(得分:2)
<fieldset>
<legend>General Info</legend>
<div>
<metal:define define-macro="widget_rendering"> <!-- not sure if this define-macro is needed -->
<span tal:define="widgets view/widgets/values">
<tal:widgets repeat="widget python:[w for w in widgets if not w.name.startswith('form.widgets.current') and not w.name.startswith('form.widgets.surrounding') and 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> <!-- to keep label and input field together -->
</div>
</fieldset>
在调整页面大小时,标题和输入框保持在一起仍然存在问题,但排序代码有效。