2007-08-22

[メモ]【訂正】TurboGearsのwidgets-based formのpre-fill

昨日のエントリーに、TurboGears×Pythonatsさんからじきじきにアドバイスが!

以下のように、フィールド名:値という内容のdictを渡し、、

class SomethingFields(widgets.WidgetsList):
code = widgets.HiddenField()
query = widgets.TextField(label=u"検索")

class SomethingSchema(validators.Schema):
code = validators.String(not_empty=True, max=9)
query = validators.String(not_empty=True, max=5)

class SomethingForm(widgets.TableForm):
fields = SomethingFields()

something_form_obj = SomethingForm(fields=SomethingFields(), validator=SomethingSchema())

class SomeController(controllers.Controller):
@expose(template='kid:somepackage.SomeController.templates.detail')
def detail(self, code, **kw):
#........
return dict(form=something_form_obj, value={"code": code})


kidのほうで、value=でその辞書を指定してやるといいのだということ。
<span>
${form(action='search', submit_text = "Search", method="get", value=value)}
<p py:if="defined('message')">${message}</p>
</span>


やはり、正統なやり方はきれいです。
ありがとうございました!