[英]How to get fields displaying in a custom plone dexterity form?
I'm trying to avoid writing out a few hundred fields in my custom addform for a plone dexterity object.我试图避免在我的自定义 addform 中为 plone 灵巧对象写出几百个字段。
i've created a loop that is called from my customVisitFormTemplate.pt我创建了一个从我的 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
in the custom template i call it with this:在自定义模板中,我这样称呼它:
<fieldset> <legend>General Info</legend> <span tal:define="otherFields view/otherFields2"> <div tal:content="structure otherFields" /> </span> </fieldset>
however, on execution the tal statement does not call the widget, and it outputs to html:但是,在执行时,tal 语句不会调用小部件,而是输出到 html:
<tal:field tal:replace="view/widgets/siteID/@@ploneform-render-widget" />
if i use the following code directly in my custom temlpate:如果我直接在我的自定义模板中使用以下代码:
<tal:field tal:replace="view/widgets/siteID/@@ploneform-render-widget" />
it outputs to html and it works:它输出到 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>
how do i get my looped code from my .py file to output the same as the "direct" code?如何从我的 .py 文件中获取循环代码以输出与“直接”代码相同的代码?
thanks for any suggestions感谢您的任何建议
after quite some playing around, i finally got this complexity working :).在玩了一段时间之后,我终于让这种复杂性起作用了:)。
<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>
here are still an issue in terms of having the title and input box stay together when resizing the page, but the sorting code works.在调整页面大小时,标题和输入框保持在一起仍然存在问题,但排序代码有效。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.