[Zope-CMF] printing out member roster grouped by custom property ZPT

David (Hamish) Harvey david.harvey@bristol.ac.uk
Wed, 17 Jul 2002 23:38:43 +0100


Kristina,

Posting in html is unpopular.

The way I've done this is a bit ugly, but it works for me at the moment. I 
have an external method (not sure if it needs to be, maybe a python script 
would do) which looks like this:

def filteredMemberList(member_tool, attribute_name, salt):

    members = member_tool.getRoster()
    filtered = []
    for member in members:
        member_obj = member_tool.getMemberById(member['id'])
        attribute_value = member_obj.getProperty(attribute_name)
        if attribute_value==salt:
            filtered.append({'id':member['id'], 'listed':member['listed']})
    return filtered

I clearly copied some of it from somewhere (I wouldn't have used the 
parameter name "salt") but I'm not sure where. This will return a subset of 
members for whom the property "attribute_name" is set to == salt. My custom 
property that I'm grouping by is called member_group, and is constrained to 
a list of values called member_classes, so I can then repeat over the items 
in member_classes in a page template, and call filteredMemberList with each.

Here's a snippet of the page template that uses it

    <div metal:fill-slot="main"
          tal:define="mtool here/portal_membership;
                      ptool here/portal_memberdata;
                      member_classes 
python:ptool.getProperty('member_classes');
                      DateTime python:modules['DateTime'].DateTime;
                      Batch python:modules['ZTUtils'].Batch;
                      DateTime python:modules['DateTime'].DateTime;
                      b_start python:request.get('b_start', 0);">

      <metal:block tal:repeat="member_class member_classes">
      <div tal:define="members python:here.filteredMemberList(mtool, 
'member_group', member_class);">

<!-- do whatever you want with each member in the group here -->

      </div>
      </metal:block>

    </div>

Cheers,
Hamish

--On Wednesday, July 17, 2002 14:24:03 -0400 Kristina Quimson Buenafe 
<kqb7a@virginia.edu> wrote:

>
> Hi,
>
> I am trying to print out the members of my CMF site (Zope 2.5.1, Plone
> 0.9.9, CMF 1.3beta1) and group them by a custom property.  For example, I
> would like to have a page that looks somewhat like this:
> Agency1
> -Person1
> -Person2
> -Person3
>
> Agency2
> -Person4
> -Person5
>
> Agency3
> -Person6
>
> and so on.
>
>
> While searching the Zope-CMF archives I found this post that addresses
> the sorting issue, but does it with DTML.  Do any of you know how to
> accomplish this by using ZPT?
> thanks,
> Kristina Buenafe
>


--
Hamish Harvey (aka David)
Network Coordinator, FloodRiskNet
Research Assistant, Water and Environmental Management Research Centre
University of Bristol, Lunsford House, Cantock's Close, Bristol BS8 1UP
Tel: +44 (117) 9289768 Fax: +44 (117) 9289770
Email: david.harvey@bristol.ac.uk/hamish@floodrisknet.org.uk
PGP Key Fingerprint: 6F15 A1C7 342F 2F87 E2CC  176D 1072 8A5B 20E8 E497
WWW: http://www.cen.bris.ac.uk/civil/pgra/dph/dph.htm