[albatross-users] A pattern for processing a bunch of items at once?

Ben Golding bgg at object-craft.com.au
Thu Oct 31 17:08:16 EST 2002


On Thursday, Oct 31, 2002, at 16:53 Australia/Melbourne, Greg Hamilton 
wrote:

> Create a checkbox for each message. Give each checkbox the same name. 
> Set the value to something which uniquely identifies the message.
>
> <al-form method="post">
> <al-for iter="element" expr="messages">
> <al-input type="checkbox" name="del_msgs" 
> valueexpr="element.value().get_message_id()" whitespace>
> </al-for>
> <al-input type="submit" name="delete" value="Delete">
> </al-form>

If you add the "list" attribute to the al-input, so that it reads:

	<al-input type="checkbox" name="del_msgs" 
valueexpr="element.value().get_message_id()" whitespace list>

then it will always return a list which will be empty, contain a single 
element, or all selected elements.  That makes the code below largely 
redundant which was why it was added.

> def page_process(ctx):
> 	if ctx.req_equals('delete'):
>         # if nothing is selected return is None
>         # if one item, return is String
>         # if >1 items, return is list
> 		if ctx.local.del_msgs is None:
> 			# nothing selected
> 			pass
>         elif type(ctx.locals.del_msgs) == types.StringType:
>         	# one message to delete
> 			pass
> 		elif type(ctx.locals.del_msgs) == types.ListType:
> 			# a list of messages to delete
> 			pass

That should simplify things.

	Ben.




More information about the Albatross-users mailing list