[Zope-dev] The #in tag and spanning multiple rows in tables

Itai Tavor itavor@vic.bigpond.net.au
Mon, 26 Apr 1999 13:46:28 +1000


I'm displaying rows of data (stored in a TinyTable) with the #in tag. The
first data column is a year, and if two or more rows have the same year I
need to show the year once in a ROWSPAN cell. The start-nnn and end-nnn
tell me when to do this, but I can't know the number of rows to span. Is
there any way to find this out?

When I couldn't find any, I patched DocumentTemplate/DT_InSV.py to return a
more-nnn variable that returns how many more items have the same nnn value
as the current item. So I can do:

<!--#if start-year-->
<DL ROWSPAN=<!--#var "_['more-year']+1"-->>
<!--#var year-->
</DL>
<!--#/if-->

But I'm really an absolute beginner in Zope... especially when it comes to
the source. Does this look like a good thing to do?

Here's the patch if anyone's interested, or if anyone wants to critique my
code:

*** DT_InSV.py.old	Mon Apr 26 13:32:05 1999
--- DT_InSV.py	Mon Apr 26 13:39:59 1999
***************
*** 193,196 ****
--- 193,209 ----
          return self.value(index,name) != self.value(index+1,name)

+     def more(self,name,key=''):
+         data=self.data
+         index=data['sequence-index']
+         if data.has_key('sequence-step-end'):
+             end=data['sequence-step-end']
+         else:
+             end=len(self.items)
+         m=0
+         for i in range(data['sequence-index'],end-1):
+             if self.value(i,name) != self.value(i+1,name): break
+             m=m+1
+         return m
+
      def length(self, ignored):
          l=self.data['sequence-length']=len(self.items)
***************
*** 362,365 ****
--- 375,379 ----
          'first': first,
          'last': last,
+         'more': more,
          'previous': previous_batches,
          'next': next_batches,
--
Itai Tavor                      -- "Je sautille, donc je suis."    --
itavor@vic.bigpond.net.au       --               - Kermit the Frog --
--                                                                 --
-- "If you haven't got your health, you haven't got anything"      --