[albatross-users] revisiting checkboxes..
Andrew McNamara
andrewm at object-craft.com.au
Thu Jun 26 10:46:43 EST 2003
>I'm still unclear on how to get a list of what isn't checked off. FYI, the
>reason I just can't go back to the original source is because it's always
>changing as more spam comes in. Storing all the information in a hidden field
>is possible but unpleasant to contemplate.
One way or another you will have to carry the list of "unchecked"
boxes across.
Some options include:
- putting the full list into the execution context (ctx.locals), provided
you're using a stateful application model.
- putting the full list into a hidden field - I'm not sure why you suggest
this is unpleasant - it's quite easy to do, and it will work with the
non-stateful application model.
- using separate names for each checkbox via the nameexpr attribute.
You might implement the last one like this (note - untested):
Page module (or page class with some modifications):
class SpamtrapTokens:
def __init__(self, token_list):
self.token_list = []
for token in token_list:
token_attr = 't_' + token
setattr(self, token_attr, 'on')
self.token_list.append(token_attr)
def selected(self):
return [attr
for attr in self.token_list
if getattr(self, attr) == 'on']
def unselected(self):
return [attr
for attr in self.token_list
if getattr(self, attr) == '']
def page_enter(ctx):
ctx.locals.spamtrap_tokens = SpamtrapTokens( ... )
Template:
<table>
<al-for iter="token_i" expr="spamtrap_tokens.token_list">
<tr>
<td>
<al-input type="checkbox" value="on" nameexpr="token_i.value()">
</td>
...
</tr>
</al-for>
</table>
--
Andrew McNamara, Senior Developer, Object Craft
http://www.object-craft.com.au/
More information about the Albatross-users
mailing list