[Zope] comparing lists in DTML | Python?

ed colmar element@immersivearts.com
Sun, 6 Feb 2000 13:24:31 -0700


 After reading Joachim Schmitz <js@ac-copy.net> post "extensive Looping in
DTML considered harmful", I have a few questions about how this relates to
my Product.  I've also been stumped on how to do this in a few situations
now.

In my python product, I have three base classes:  promoter, event, and
person

Inside of the promoter class there is a list variable called promoterdjs.

Inside of the person class there is a string varialbe called djname.

In my dtml, I have a page which displays the promoter, and checks to see if
any of the djnames match with the items in promoterdj.  If they match, I
want to hyperlink them to the id of that dj.

The code I have been hacking at looks like this:

    <dtml-if promotiondjs><strong><font size="+1"><dtml-var
promotionname></font> DJs:</strong><BR>
        <dtml-with "PARENTS[0]">
              <dtml-in promotiondjs><dtml-let thisdj=sequence-item>
                  <dtml-in personValues>
                     <dtml-if "meta_type == 'SRPersonPost'">
                        <dtml-if "_.str(thisdj) == _.str(djname)">
                           <A href="<dtml-var site_url>/<dtml-var
id>"><dtml-var thisdj></a><br>
                        <dtml-else><dtml-var thisdj><BR>
                        </dtml-if>
                     </dtml-if>
                   </dtml-in>
                 </dtml-let>
              </dtml-in>
        </dtml-with>
    <dtml-else>
    This promoter has no dj's associcated with it.
    </dtml-if promotiondjs>

NOTE!  this produces this output with two dj's that match:

dj1
dj1 # with anchor
dj2 # with snchor
dj2
dj3
dj3


My question is:  How would this be achieved in python, and what is the
proper way to do it in DTML?  Would the python look something like:

    def compareDJs(self,promoterdjs):   ## untested  ##
        """ return the input list as a tuple, with ids attached
            if none are found return the tuple with '0'
        """
        persidlist = map(None,self.ids)
        for i in len(promoterdjs):
            personidlist = persidlist
            personidlist = filter(lambda x,p=self : p.data[x].meta_type ==
'SRPersonPost', personidlist)
            personidlist = filter(lambda x,p=self : p.data[x].promotername
== promoterdj[i], personidlist)
            personids.append(personidlist)
        return map(None, promoterdjs, personids)


Thanks for any input!

-ed-