products/CPSSubscriptions

changeset 1065:9294ea67e4c5 CPS-3.5

#2049: draft for main UI macro
author Georges Racinet on purity.racinet.fr <georges@racinet.fr>
date Thu, 29 Sep 2011 22:43:15 +0200
parents e36d8b80e4e0
children d556b73e7e72
files SubscriptionsTool.py skins/cps_subscriptions/folder_notifications_all_subscribers_view.pt
diffstat 2 files changed, 38 insertions(+), 5 deletions(-) [+]
line diff
     1.1 --- a/SubscriptionsTool.py
     1.2 +++ b/SubscriptionsTool.py
     1.3 @@ -39,6 +39,7 @@
     1.4  from Acquisition import aq_parent, aq_inner, aq_base
     1.5  from AccessControl import ClassSecurityInfo
     1.6  from AccessControl import Unauthorized
     1.7 +from ZTUtils import make_query
     1.8  
     1.9  from zope.interface import implements
    1.10  
    1.11 @@ -962,9 +963,10 @@
    1.12            - groups
    1.13            - other
    1.14  
    1.15 -        Values are themselves dicts whose keys are ids in corresponding
    1.16 -        directories and values the list of events for which the recipient
    1.17 -        is notified.
    1.18 +        For easy iteration in page templates, values are lists of dicts,
    1.19 +        with these keys:
    1.20 +           + id : the recipient id, whose meaning depends on the category
    1.21 +           + events : list of events the recipient is being notified for
    1.22          """
    1.23  
    1.24          if not _checkPermission(ViewSubscriptions, obj):
    1.25 @@ -975,12 +977,42 @@
    1.26          other = {}
    1.27          recipients = dict(members=members, groups=groups, other=other)
    1.28  
    1.29 +        aclu = getToolByName(self, 'acl_users')
    1.30 +        utool = getToolByName(self, 'portal_url')
    1.31 +        dtool = getToolByName(self, 'portal_directories')
    1.32 +        base_url = utool.getBaseUrl()
    1.33 +
    1.34          def record(category, recipient, event):
    1.35              """Record that a recipient of category is notified for event_type.
    1.36  
    1.37              Category is one of our three dicts
    1.38              """
    1.39 -            category.setdefault(recipient, []).append(event)
    1.40 +            logger.debug("Recording %r for %r in %r",
    1.41 +                         recipient, event, category)
    1.42 +            rec_dict = category.get(recipient)
    1.43 +            if rec_dict is None:
    1.44 +                category[recipient] = rec_dict = dict(id=recipient, events=[])
    1.45 +
    1.46 +                if category is members:
    1.47 +                    attr = 'users_dir'
    1.48 +                elif category is groups:
    1.49 +                    attr = 'groups_dir'
    1.50 +                else:
    1.51 +                    attr = None
    1.52 +
    1.53 +                if attr:
    1.54 +                    dirname = getattr(aclu, attr)
    1.55 +                    dirobj = dtool[dirname]
    1.56 +                    try:
    1.57 +                        entry = dirobj.getEntry(recipient)
    1.58 +                    except Unauthorized:
    1.59 +                        pass
    1.60 +                    else:
    1.61 +                        rec_dict['link'] = '%scpsdirectory_entry_view?%s' % (
    1.62 +                            base_url, make_query(dirname=dirname, id=recipient))
    1.63 +                        rec_dict['title'] = entry[dirobj.title_field]
    1.64 +
    1.65 +            rec_dict['events'].append(event)
    1.66  
    1.67          expand_groups = not self.use_group_emails
    1.68  
     2.1 --- a/skins/cps_subscriptions/folder_notifications_all_subscribers_view.pt
     2.2 +++ b/skins/cps_subscriptions/folder_notifications_all_subscribers_view.pt
     2.3 @@ -4,7 +4,8 @@
     2.4      <h1 i18n:translate="heading_all_subscribers">
     2.5        All Subscribers
     2.6      </h1>
     2.7 -    <metal:block use-macro="here/subscriptions_lib_display_all_notifications_subscribers/macros/display_all_notifications_subscribers" />
     2.8 +    <metal:block
     2.9 +      use-macro="here/subscriptions_lib_display_detailed_recipients/macros/display" />
    2.10    </metal:block>
    2.11   </metal:block>
    2.12  </tal:block>
    2.13 \ No newline at end of file