[Twisted-Python] Generate select options in woven
Philippe Lafoucrière
lafou at wanadoo.fr
Mon Dec 8 11:33:14 EST 2003
> I've tried several variations of view='List' and view='KeyedList'
> on the select tag, using the above models, without success.
> The nearest I've been able to get is one of the following:
> <option value='id1'>id1</option>
> <option value='value1'>value1</option>
> <option value='id1'>value1id1</option>
I never succeded in using KeyedList :(
****************************
with :
wmfactory_versions = [
('id1', 'value1'),
('id2', 'value2'),
('id3', 'value3')]
You can do that :
def wvupdate_display_value(self, request, node, model):
option = microdom.lmx(node)
option['value'] = model
display = request.args.get("display", [""])[0]
if display == model:
option['selected'] = "1"
And change
<option view="display_value" value="thevalue">
<span view="Text"></span>
</option>
to
<option view="display_value" value="thevalue" model="0">
<span view="Text" model="1"></span>
</option>
(not tested, but it should work).
** OR ************
if you really want to use a dict like
wmfactory_versions = {
{val='id1', desc='value1'},
{val='id2', desc='value2'},
{val='id3', desc='value3'} }
then put this in your template :
<option view="display_value" value="thevalue" model="/id">
<span view="Text" model="/desc"></span>
</option>
see http://www.twistedmatrix.com/documents/howto/modelindepth#submodelpaths
for more infos.
********************
Btw, I think woven should remove empty <span> tags from outputs. I'll post a
bug report for that.
********************
if you want some exemple code, you can download this :
http://wwwetu.utc.fr/~plafoucr/gat/gat.tzg
it's a frontend to Portage (the gentoo package manager). It's in progress, and
lacks most of its features, but some code parts may help you.
good luck !
Philippe
More information about the Twisted-Python
mailing list