[Zope] sequence of numbers

Eric Kidd eric.kidd@pobox.com
Sat, 13 Mar 1999 14:47:48 -0500


On Fri, Mar 12, 1999 at 06:26:42PM -0800, Bill Randle wrote:
> This may be a newbie question, but I've loked thru the doc and didn't
> spot any obvious way to do this, short of an External Method.

I didn't find any other way, either. But here's an External Method you can
use.

--- begin loop_range.py ---
LoopRangeError = 'LoopRangeError' # Name an exception class.
loop_range_limit = 100            # Maximum allowable loop index.

def loop_range(max):
    if max <= loop_range_limit:
	return range(max)
    else:
	raise LoopRangeError, max
--- end ---

Notice that it won't allow the "max" parameter to be bigger than 100. This
prevents users from generating near-infinite amounts of HTML and freezing
your server. You can edit this to any value you like, or even remove it if
you trust all your DTML authors.

Now, create an External method with the following properties:

  id:     loop_range
  title:  Loop Iteration Method
  method: loop_range
  file:   loop_range

To use this method in DTML, try the expr attribute of the #in construct:

--- begin sample DTML ---
<!--#in expr="loop_range(max=50)"-->
<P>Index: <!--#var sequence-item--></P>
<!--#/in-->
--- end ---

> Is there an easy way to do this? Is there *any* way to do it?

Yup. ;-) Zope has tons of power hiding under the hood, and a skilled Python
programmer could make it do almost anything.

Cheers,
Eric