
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'> <n:attr name='value'><n:slot name='value'/></n:attr> <n:slot name='city'/> </option> </select> def data_cityList( self, context, data ): return [("New York",'1'), ("Los Angeles",'2')] def render_city( self, context, (city, value) ): context.fillSlots( 'value', value ) context.fillSlots( 'city', city ) 'sequence' is a built-in renderer that takes a list as data, and repeats the nested 'item' pattern with each element of the list as data. It also accepts patterns 'header', 'footer', and 'divider', but those arn't useful in this case. The data_cityList is changed to return a list of tuples, otherwise you will have no control over the order of the items. Also, this uses <n:attr>, which was just added to svn less than a day ago, and atm only works with xmlfile. This allows putting slots in attributes. Alternately, for something that doesn't use <n:attr> and isn't as verbose, you could do: <select n:render='sequence' n:data='cityList'> <option n:render='city' n:pattern='item'> the contents of this node don't matter </option> <select> and change render_city to return a literal stan tag: def render_city( self, context, (city, value) ): from nevow.tags import * return option( value=value )[city] 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?
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