How do I construct a method of an object, so that whenever that method is called, the current namespace is passed with it? I.e.: class myclass: [...] def myfunc(self, context): if context['sequence-index'] == 10: raise 'sequence-index is %s' % \ context['sequence-index'] called from DTML, like so: <dtml-in "objectValues('Spam')"> <dtml-var myfunc> </dtml-in> will raise an exception if sequence-index is 10 or more? Specifically, the reason I want this function is that I feel using <dtml-if sequence-even> <tr bgcolor="<dtml-var color_sequence_even>"> <dtml-else> <tr bgcolor="<dtml-var color_sequence_odd>"> </dtml-if> is a bit tedious (and ugly!) in the long run.. If this isn't implemented, where would the right place to implement it be? -Morten
Morten W. Petersen wrote:
Specifically, the reason I want this function is that I feel using
<dtml-if sequence-even> <tr bgcolor="<dtml-var color_sequence_even>"> <dtml-else> <tr bgcolor="<dtml-var color_sequence_odd>"> </dtml-if>
is a bit tedious (and ugly!) in the long run..
If this is what you want to do, there's an easier way from DTML: <dtml-let colours="('blue', 'yellow', 'green')" num_colours="_.len(colours)"> <dtml-in "_.range(10)"> <dtml-let row_index=sequence-index colour="colours[row_index % num_colours]"> <font color=&dtml-colour;> this is row &dtml-sequence-item; </font><br> </dtml-let> </dtml-in> </dtml-let> -- Steve Alexander Software Engineer Cat-Box limited http://www.cat-box.net
participants (2)
-
morten@esol.no -
Steve Alexander