[Zope] Finding matches between two lists

ed colmar element@immersivearts.com
Fri, 03 Mar 2000 09:14:00 -0700


Hey all!

	This question went by last month without a reply, so I am going to try it
again.  I've also gotten a bit closer to the answer on my own.

	---------

	The layout:

	Most of my code is in a Python Product, but there is still a bunch of dtml
used.

	I have a class called "person" with a string variable called "name",  and
a class called "event" with a list variable called "eventnames".

	Now when a addEventForm is filled out, then the viewEventPage is called, I
want all the people listed in "eventnames" to have a link to thier home
page if they exist.

	---------

	The DTML attempt:

	I could never get this to work correctly.  Becuase it is looking through
two lists, the code causes the "eventnames" to be dispayed once for each
person listed.

	<dtml-if eventnames><BR><BR><STRONG>Featuring people :</STRONG>     
        <dtml-with "PARENTS[0]">
          <dtml-in personValues>
            <dtml-if "meta_type == 'SRPersonPost'">
              <dtml-in eventnames>
                 <dtml-if "_['sequence-item'] == name">
                   <A href="<dtml-var site_url>/<dtml-var id>"><dtml-var
sequence-item></a>, 
                 <dtml-else><dtml-var sequence-item>, 
                 </dtml-if>
              </dtml-in>
            </dtml-if>
          </dtml-in>
        </dtml-with>
    </dtml-if eventnames>


	---------

	The Python attempt:

	So I tried to change my strategy, and build a method to find the matches,
and return the list with the ids (if the person is listed) or a 'None' if
they are not listed.  I haven't been able to figure out what is going wrong
with this.

    def list_dj_list(self, namelist):
        """ should return a list of names & IDs from a list of names
        """
        rlist = map(None,self.ids)
        rlist = filter(lambda x,p=self : p.data[x].validated, rlist)
        rlist = filter(lambda x,p=self : p.data[x].meta_type ==
'SRPersonPost', rlist)
        rlist = filter(lambda x,p=self : p.data[x].name, rlist)
        rnames = []
        for i in range(len(namelist)):
            rnamelist = rlist
            rname = filter(lambda x,p=self,s=namelist[i] : p.data[x].name
== s, rnamelist)
            if len(rnames) == 0:
                rnames.append('None')
            elif len(rnames) == 1:
                rnames.append(rname)
            else:
                rnames.append('multiples')

        return rnames

	---------

	The question:

	How can this be achieved?  I don't have a preferance over dtml or python,
but it seems like a python method is the proper way to do it.

	Thanks for any help!

	-ed-