This works, but I think the approach might be wrong. (the output is what I want it to be, but I think I may have implemented things counter to the way nevow was designed) Can someone please offer their input? template.html ------------------- <tr> <td valign="top"> pick a city</td> <td> <select name="city"> <span nevow:data="citiesList" nevow:render="city"></span> </select> </td> </tr> testing.py ------------------- def data_citiesList(self, context, data): return {"New York":'1', "Los Angeles":'2'} def render_city(self, context, data): """Example of using stan to render a page. """ return rend.stan( [ T.option(value=v)[k] for (k,v) in data.items() ] ) Output.html ---------------- <tr> <td valign="top"> pick a city</td> <td> <select name="city"> <option value=1>New York</option> <option value=2>Los Angeles</option> </select> </td> </tr>
On Tue, Apr 13, 2004 at 12:43:09AM -0400, jonathan vanasco wrote:
This works, but I think the approach might be wrong. (the output is what I want it to be, but I think I may have implemented things counter to the way nevow was designed)
Can someone please offer their input?
Sure, see comments inline with code. Please bear in mind I haven't executed this code, I'm just making it up ;)
template.html ------------------- <tr> <td valign="top"> pick a city</td> <td> <select name="city"> <span nevow:data="citiesList" nevow:render="city"></span> </select> <select name="city" nevow:data="citiesList" nevow:render="city" /> </td> </tr>
testing.py ------------------- def data_citiesList(self, context, data): return {"New York":'1', "Los Angeles":'2'} def render_city(self, context, data): """Example of using stan to render a page. """ return rend.stan( [ T.option(value=v)[k] for (k,v) in data.items() ] )
return context.tag[ [ T.option(value=v)[k] for (k,v) in data.items() ] ]
Output.html ---------------- <tr> <td valign="top"> pick a city</td> <td> <select name="city"> <option value=1>New York</option> <option value=2>Los Angeles</option> </select> </td> </tr>
Regards, Stephen Thorne
jonathan vanasco wrote:
Can someone please offer their input?
The following is a bit more graphic designer friendly:
template.html ------------------- <tr> <td valign="top"> pick a city</td> <td> <select name="city"> <span nevow:data="citiesList" nevow:render="city"></span> </select> </td> </tr>
<select name="city" nevow:data="citiesList" nevow:render="sequence"> <option nevow:pattern="item" nevow:render="city" value="1"> </option> </select>
testing.py ------------------- def data_citiesList(self, context, data): return {"New York":'1', "Los Angeles":'2'} def render_city(self, context, data): """Example of using stan to render a page. """ return rend.stan( [ T.option(value=v)[k] for (k,v) in data.items() ] )
def data_citiesList(self, context, data): return {"New York":'1', "Los Angeles":'2'}.items() def render_city(self, context, data): return context.tag(value=data[1])[data[0]] The only problem with the above is if you put something inside the option for the template, say: <option nevow:pattern="item" nevow:render="city" value="1"> ned </option> You will see ned prepended in each option rendered by nevow. Does anyone know how to overwrite the template contents of the option? cheers, Andy.
On Tue, Apr 13, 2004 at 04:08:31PM +1000, Andy Gayton wrote:
def data_citiesList(self, context, data): return {"New York":'1', "Los Angeles":'2'}.items()
def render_city(self, context, data): return context.tag(value=data[1])[data[0]]
The only problem with the above is if you put something inside the option for the template, say:
<option nevow:pattern="item" nevow:render="city" value="1"> ned </option>
You will see ned prepended in each option rendered by nevow. Does anyone know how to overwrite the template contents of the option?
def render_city(self, context, data): return context.tag.clear()(value=data[1])[data[0]] .clear() returns self, so you can chain it like that. Stephen.
Another option:
<select n:render='sequence' n:data='cityList'>
<option n:render='city' n:pattern='item'>
This works, but I think the approach might be wrong. (the output is what I want it to be, but I think I may have implemented things counter to the way nevow was designed)
Can someone please offer their input?
template.html ------------------- <tr> <td valign="top"> pick a city</td> <td> <select name="city"> <span nevow:data="citiesList" nevow:render="city"></span> </select> </td> </tr>
testing.py ------------------- def data_citiesList(self, context, data): return {"New York":'1', "Los Angeles":'2'} def render_city(self, context, data): """Example of using stan to render a page. """ return rend.stan( [ T.option(value=v)[k] for (k,v) in data.items() ] )
Output.html ---------------- <tr> <td valign="top"> pick a city</td> <td> <select name="city"> <option value=1>New York</option> <option value=2>Los Angeles</option> </select> </td> </tr>
_______________________________________________ Twisted-web mailing list Twisted-web@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-web
participants (4)
-
Andy Gayton
-
indigo@bitglue.com
-
jonathan vanasco
-
Stephen Thorne