[Zope3-checkins] SVN: Zope3/trunk/src/zope/app/pas/principalplugins. Changed the default factory plugin to be a global plugin.

Jim Fulton jim at zope.com
Wed Oct 13 13:01:33 EDT 2004


Log message for revision 28112:
  Changed the default factory plugin to be a global plugin.
  
  Also added a subscriber that adds a title and description if they are
  found in info.
  

Changed:
  U   Zope3/trunk/src/zope/app/pas/principalplugins.py
  U   Zope3/trunk/src/zope/app/pas/principalplugins.zcml

-=-
Modified: Zope3/trunk/src/zope/app/pas/principalplugins.py
===================================================================
--- Zope3/trunk/src/zope/app/pas/principalplugins.py	2004-10-13 17:00:56 UTC (rev 28111)
+++ Zope3/trunk/src/zope/app/pas/principalplugins.py	2004-10-13 17:01:31 UTC (rev 28112)
@@ -16,15 +16,13 @@
 $Id$
 """
 __docformat__ = "reStructuredText"
-from persistent import Persistent
 
 from zope.event import notify
 from zope.interface import implements
 
-from zope.app.container.contained import Contained
 from zope.app.security.interfaces import IPrincipal
 
-import interfaces
+from zope.app.pas import interfaces
 
 class Principal:
     """A simple Principal
@@ -52,7 +50,7 @@
         return 'Principal(%r)' %self.id
 
 
-class PrincipalFactory(Persistent, Contained):
+class PrincipalFactory:
     """A simple principal factory.
 
     First we need to register a simple subscriber that records all events.
@@ -103,3 +101,43 @@
         principal = Principal(id)
         notify(interfaces.FoundPrincipalCreated(principal, info))
         return principal
+
+def addTitleAndDescription(event):
+    """Set title and description from info
+
+    We can set title and description information for principals if keys
+    can be found in the info:
+
+      >>> principal = Principal('3')
+      >>> event = interfaces.FoundPrincipalCreated(
+      ...    principal, {'title': u'Bob', 'description': u'Eek'})
+      >>> addTitleAndDescription(event)
+      
+      >>> principal.title
+      u'Bob'
+      >>> principal.description
+      u'Eek'
+
+    Note that the attributes are only set if they aren't set already:  
+
+      >>> event = interfaces.FoundPrincipalCreated(
+      ...    principal, {'title': u'Fred', 'description': u'Dude'})
+      >>> addTitleAndDescription(event)
+      
+      >>> principal.title
+      u'Bob'
+      >>> principal.description
+      u'Eek'
+
+    """
+
+    principal = event.principal
+    info = event.info
+
+    title = info.get('title')
+    if title and not principal.title:
+        principal.title = title
+
+    description = info.get('description')
+    if description and not principal.description:
+        principal.description = description

Modified: Zope3/trunk/src/zope/app/pas/principalplugins.zcml
===================================================================
--- Zope3/trunk/src/zope/app/pas/principalplugins.zcml	2004-10-13 17:00:56 UTC (rev 28111)
+++ Zope3/trunk/src/zope/app/pas/principalplugins.zcml	2004-10-13 17:01:31 UTC (rev 28112)
@@ -4,26 +4,15 @@
     i18n_domain="zope"
     >
 
-  <browser:tool
-      interface=".interfaces.IPrincipalFactoryPlugin"
-      title="PAS Principal Factory Plugin"
-      description="PAS Principal Factory Plugin"
+  <utility
+      provides=".interfaces.IPrincipalFactoryPlugin"
+      name="Default"
+      factory=".principalplugins.PrincipalFactory"
       />
 
-  
-  <localUtility class=".principalplugins.PrincipalFactory">
-
-    <implements
-        interface="zope.app.annotation.interfaces.IAttributeAnnotatable" />
-
-  </localUtility>
-
-
-  <browser:addMenuItem
-      title="PAS Principal Factory Plugin"
-      description="A PAS Principal Factory Plugin"
-      class=".principalplugins.PrincipalFactory"
-      permission="zope.ManageServices"
+  <subscriber
+      for=".interfaces.IPASPrincipalCreated"
+      factory=".principalplugins.addTitleAndDescription"
       />
 
 </configure>



More information about the Zope3-Checkins mailing list