[CMF-checkins] CVS: CMF/CMFDefault - DiscussionItem.py:1.36.2.1 DublinCore.py:1.29.2.1

Yvo Schubbe schubbe at web.de
Fri Dec 19 09:37:35 EST 2003


Update of /cvs-repository/CMF/CMFDefault
In directory cvs.zope.org:/tmp/cvs-serv6937/CMFDefault

Modified Files:
      Tag: yuppie-collector025-branch
	DiscussionItem.py DublinCore.py 
Log Message:
- added listCreators and listContributors to DublinCore interface
- implemented these methods in DefaultDublinCoreImpl
- added addCreator method to DefaultDublinCoreImpl and made it called by notifyModified
- updated DiscussionItem to use the new interface


=== CMF/CMFDefault/DiscussionItem.py 1.36 => 1.36.2.1 ===
--- CMF/CMFDefault/DiscussionItem.py:1.36	Sun Nov 16 04:43:18 2003
+++ CMF/CMFDefault/DiscussionItem.py	Fri Dec 19 09:37:04 2003
@@ -21,18 +21,15 @@
 from OFS.Traversable import Traversable
 from DateTime import DateTime
 
-from Products.CMFCore.CMFCorePermissions import View
 from Products.CMFCore.CMFCorePermissions import AccessContentsInformation
-from Products.CMFCore.CMFCorePermissions import ReplyToItem
 from Products.CMFCore.CMFCorePermissions import ManagePortal
+from Products.CMFCore.CMFCorePermissions import ReplyToItem
+from Products.CMFCore.CMFCorePermissions import View
+from Products.CMFCore.interfaces.Discussions import Discussable
+from Products.CMFCore.interfaces.Discussions import DiscussionResponse
 from Products.CMFCore.utils import getToolByName
-from Products.CMFCore.PortalContent import PortalContent
 
 from Document import Document
-from DublinCore import DefaultDublinCoreImpl
-
-from Products.CMFCore.interfaces.Discussions import DiscussionResponse
-from Products.CMFCore.interfaces.Discussions import Discussable
 
 
 factory_type_information = (
@@ -73,9 +70,9 @@
 
     Otherwise, same as addDocument
     """
-    
+
     if not description: description = title
-    text = scrubHTML(text) 
+    text = scrubHTML(text)
     item = DiscussionItem( id )
     item.title = title
     item.description = description
@@ -89,38 +86,36 @@
     if RESPONSE is not None:
         RESPONSE.redirect(self.absolute_url())
 
-    
-class DiscussionItem( Document
-                    , DefaultDublinCoreImpl
-                    ):
+
+class DiscussionItem(Document):
     """
         Class for content which is a response to other content.
     """
 
-    __implements__ = ( DiscussionResponse
-                     , PortalContent.__implements__
-                     , DefaultDublinCoreImpl.__implements__
-                     )
+    __implements__ = (DiscussionResponse, Document.__implements__)
 
     meta_type           = 'Discussion Item'
     portal_type         = 'Discussion Item'
     allow_discussion    = 1
-    creator             = 'unknown'
     in_reply_to         = None
     # XXX this is wrong, it precludes the use of a normal workflow.
     review_state        ='published'
 
     security = ClassSecurityInfo()
 
-    security.declareProtected(View, 'Creator')
-    def Creator( self ):
-        """
-            We need to return user who replied, rather than executable
-            owner.
-        """
-        #   XXX:  revisit if Creator becomes "real" attribute for stock DC.
-        return self.creator
-    
+    security.declareProtected(View, 'listCreators')
+    def listCreators(self):
+        """ List Dublin Core Creator elements - resource authors.
+        """
+        if not hasattr(self, 'creators'):
+            # for content created with CMF versions before 1.5
+            owner = self.getOwner()
+            if self.creator and self.creator != 'unknown':
+                self.creators = ( self.creator, )
+            else:
+                self.creators = ()
+        return self.creators
+
     #
     #   DiscussionResponse interface
     #
@@ -134,7 +129,7 @@
               - We are a "top-level" reply to a non-DiscussionItem piece
                 of content;  in this case, our 'in_reply_to' field will
                 be None.
-            
+
               - We are a nested reply;  in this case, our 'in_reply_to'
                 field will be the ID of the parent DiscussionItem.
         """
@@ -151,7 +146,7 @@
             self.in_reply_to = reply_to.getId()
         else:
             self.in_reply_to = None
-    
+
     security.declareProtected(View, 'parentsInThread')
     def parentsInThread( self, size=0 ):
         """
@@ -174,6 +169,7 @@
 
 InitializeClass( DiscussionItem )
 
+
 class DiscussionItemContainer( Persistent, Implicit, Traversable ):
     """
         Store DiscussionItem objects. Discussable content that
@@ -305,12 +301,12 @@
         item._edit( text_format=text_format, text=text )
 
         if Creator:
-            item.creator = Creator
+            item.__of__(self).addCreator(Creator)
 
         item.__of__( self ).indexObject()
 
         item.setReplyTo( self._getDiscussable() )
- 
+
         self._container[ id ] = item
 
         return id
@@ -340,10 +336,10 @@
             Test to see if there are any dicussion items
         """
         outer = self._getDiscussable( outer=1 )
-        if content_obj == outer: 
+        if content_obj == outer:
             return not not len( self._container )
         else:
-            return not not len( content_obj.talkback._getReplyResults() ) 
+            return not not len( content_obj.talkback._getReplyResults() )
 
     security.declareProtected(View, 'replyCount')
     def replyCount( self, content_obj ):
@@ -392,9 +388,9 @@
             Return this object's contents in a form suitable for inclusion
             as a quote in a response.
         """
- 
+
         return ""
-    
+
     #
     #   Utility methods
     #
@@ -409,7 +405,6 @@
             return outer
         parent = self._container[ in_reply_to ].__of__( aq_inner( self ) )
         return parent.__of__( outer )
-        
 
     security.declarePrivate( '_getDiscussable' )
     def _getDiscussable( self, outer=0 ):
@@ -441,5 +436,3 @@
         return result
 
 InitializeClass( DiscussionItemContainer )
-
-


=== CMF/CMFDefault/DublinCore.py 1.29 => 1.29.2.1 ===
--- CMF/CMFDefault/DublinCore.py:1.29	Mon Dec 15 11:20:22 2003
+++ CMF/CMFDefault/DublinCore.py	Fri Dec 19 09:37:04 2003
@@ -27,6 +27,7 @@
 from Products.CMFCore.interfaces.DublinCore import CatalogableDublinCore
 from Products.CMFCore.interfaces.DublinCore import DublinCore
 from Products.CMFCore.interfaces.DublinCore import MutableDublinCore
+from Products.CMFCore.utils import getToolByName
 from Products.CMFCore.WorkflowCore import WorkflowAction
 
 from utils import tuplize, _dtmldir, semi_split
@@ -56,6 +57,7 @@
         now = DateTime()
         self.creation_date = now
         self.modification_date = now
+        self.creators = ()
         self._editMetadata( title
                           , subject
                           , description
@@ -77,13 +79,25 @@
 
     security.declarePrivate('notifyModified')
     def notifyModified(self):
+        """ Take appropriate action after the resource has been modified.
+
+        Update creators and modification_date.
         """
-        Take appropriate action after the resource has been modified.
-        For now, change the modification_date.
-        """
-        # XXX This could also store the id of the user doing modifications.
+        self.addCreator()
         self.setModificationDate()
 
+    security.declareProtected(ModifyPortalContent, 'addCreator')
+    def addCreator(self, creator=None):
+        """ Add creator to Dublin Core creators.
+        """
+        if creator is None:
+            mtool = getToolByName(self, 'portal_membership')
+            creator = mtool.getAuthenticatedMember().getId()
+
+        # call self.listCreators() to make sure self.creators exists
+        if creator and not creator in self.listCreators():
+            self.creators = self.creators + (creator, )
+
     # XXX Could this be simply protected by ModifyPortalContent ?
     security.declarePrivate('setModificationDate')
     def setModificationDate(self, modification_date=None):
@@ -105,16 +119,25 @@
         """
         return self.title
 
+    security.declareProtected(View, 'listCreators')
+    def listCreators(self):
+        """ List Dublin Core Creator elements - resource authors.
+        """
+        if not hasattr(self, 'creators'):
+            # for content created with CMF versions before 1.5
+            owner = self.getOwner()
+            if hasattr(owner, 'getId'):
+                self.creators = ( owner.getId(), )
+            else:
+                self.creators = ()
+        return self.creators
+
     security.declareProtected(View, 'Creator')
-    def Creator( self ):
-        """ Dublin Core Creator element - resource creator.
+    def Creator(self):
+        """ Dublin Core Creator element - resource author.
         """
-        # XXX: fixme using 'portal_membership' -- should iterate over
-        #       *all* owners
-        owner = self.getOwner()
-        if hasattr( owner, 'getId' ):
-            return owner.getId()
-        return 'No owner'
+        creators = self.listCreators()
+        return creators and creators[0] or ''
 
     security.declareProtected(View, 'Subject')
     def Subject( self ):
@@ -135,12 +158,17 @@
         # XXX: fixme using 'portal_metadata'
         return 'No publisher'
 
-    security.declareProtected(View, 'Contributors')
-    def Contributors( self ):
+    security.declareProtected(View, 'listContributors')
+    def listContributors(self):
         """ Dublin Core Contributor elements - resource collaborators.
         """
-        # XXX: fixme
         return self.contributors
+
+    security.declareProtected(View, 'Contributors')
+    def Contributors(self):
+        """ Deprecated alias of listContributors.
+        """
+        return self.listContributors()
 
     security.declareProtected(View, 'Date')
     def Date( self ):




More information about the CMF-checkins mailing list