[CMF-checkins] CVS: CMF/CMFDefault - Document.py:1.38 DublinCore.py:1.15 NewsItem.py:1.14

Andrew Sawyers andrew@zope.com
Thu, 6 Dec 2001 16:10:40 -0500


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

Modified Files:
	Document.py DublinCore.py NewsItem.py 
Log Message:

----------------------------------------------------------------------
*tracker #386 refactoring out the metadata edits from _edit
*moved reindexObject to the 'presentation' level methods (edit,
PUT, and editMetadata)
*made test work with the refactoring
*add utils.py to tests to handle the fakeRequest and fakeResponse
classes for the PUT functionality.



=== CMF/CMFDefault/Document.py 1.37 => 1.38 ===
         self.description = description
         self.text = text
-        self.text_format = text_format
-        self._edit( text_format=text_format, text=text )
+        self.setFormat(value=text_format)
 
     security.declareProtected(CMFCorePermissions.ModifyPortalContent,
                               'manage_edit')
@@ -124,17 +123,12 @@
                 + '?manage_tabs_message=Document+updated'
                 )
 
-    def _edit(self, text_format, text, file='', safety_belt=''):
+    def _edit(self, text, text_format='', safety_belt=''):
         """ Edit the Document - Parses headers and cooks the body"""
-        self.text = text
         headers = {}
-        if file and (type(file) is not type('')):
-            contents=file.read()
-            if contents:
-                text = self.text = contents
-
-        headers, body, cooked, format = self.handleText(text, text_format)
-
+        level = self._stx_level
+        if not text_format:
+            text_format = self.text_format
         if not safety_belt:
             safety_belt = headers.get('SafetyBelt', '')
         if not self._safety_belt_update(safety_belt=safety_belt):
@@ -144,11 +138,40 @@
                    " browser 'back' button, but will have to apply them"
                    " to a freshly fetched copy.)")
             raise 'EditingConflict', msg
+        if text_format == 'html':
+            self.text = self.cooked_text = text
+        else:
+            cooked = _format_stx(text=text, level=level)
+            self.cooked_text = cooked
+            self.text = text
 
-        self.text_format = format
-        self.cooked_text = cooked
-        self.text = body
+    security.declareProtected( CMFCorePermissions.ModifyPortalContent, 'edit' )
+    def edit( self
+            , text_format
+            , text
+            , file=''
+            , safety_belt=''
+            ):
+        """
+        *used to be WorkflowAction(_edit)
+        To add webDav support, we need to check if the content is locked, and if
+        so return ResourceLockedError if not, call _edit.
 
+        Note that this method expects to be called from a web form, and so
+        disables header processing
+        """
+        self.failIfLocked()
+        if file and (type(file) is not type('')):
+            contents=file.read()
+            if contents:
+                text = self.text = contents
+        text = bodyfinder(text)
+        self.setFormat(value=text_format)
+        self._edit(text=text, text_format=text_format, safety_belt=safety_belt)
+        self.reindexObject()
+
+    security.declareProtected(CMFCorePermissions.ModifyPortalContent, 'setMetadata')
+    def setMetadata(self, headers):
         headers['Format'] = self.Format()
         new_subject = keywordsplitter(headers)
         headers['Subject'] = new_subject or self.Subject()
@@ -156,7 +179,6 @@
         for key, value in self.getMetadataHeaders():
             if key != 'Format' and not haveheader(key):
                 headers[key] = value
-        
         self._editMetadata(title=headers['Title'],
                           subject=headers['Subject'],
                           description=headers['Description'],
@@ -168,29 +190,6 @@
                           rights=headers['Rights'],
                           )
 
-    security.declareProtected( CMFCorePermissions.ModifyPortalContent, 'edit' )
-    def edit( self
-            , text_format
-            , text
-            , file=''
-            , safety_belt=''
-            , FIRST_LINE_COLON=re.compile( r'^.*:.*' )
-            ):
-        """
-        *used to be WorkflowAction(_edit)
-        To add webDav support, we need to check if the content is locked, and if
-        so return ResourceLockedError if not, call _edit.
-
-        Note that this method expects to be called from a web form, and so
-        disables header processing
-        """
-        self.failIfLocked()
-        if text_format == 'structured-text' and FIRST_LINE_COLON.match( text ):
-            # WAAAA! Inject line to disable header munging.
-            text = '\n%s' % text
-
-        self._edit(text_format, text, file, safety_belt)
-
     security.declarePrivate('guessFormat')
     def guessFormat(self, text):
         """ Simple stab at guessing the inner format of the text """
@@ -201,12 +200,9 @@
     def handleText(self, text, format=None, stx_level=None):
         """ Handles the raw text, returning headers, body, cooked, format """
         headers = {}
-        body = cooked = text
         level = stx_level or self._stx_level
-
         if not format:
             format = self.guessFormat(text)
-
         if format == 'html':
             parser = SimpleHTMLParser()
             parser.feed(text)
@@ -215,13 +211,12 @@
                 headers['Title'] = parser.title
             bodyfound = bodyfinder(text)
             if bodyfound:
-                cooked = body = bodyfound
+                body = bodyfound
         else:
             headers, body = parseHeadersBody(text, headers)
-            cooked = _format_stx(text=body, level=level)
             self._stx_level = level
 
-        return headers, body, cooked, format
+        return headers, body, format
             
     security.declarePublic( 'getMetadataHeaders' )
     def getMetadataHeaders(self):
@@ -334,7 +329,7 @@
                              'setFormat' )
     def setFormat(self, value):
         value = str(value)
-        if value == 'text/html':
+        if value == 'text/html' or value == 'html':
             self.text_format = 'html'
         else:
             self.text_format = 'structured-text'
@@ -355,7 +350,10 @@
         else: self.setFormat('text/plain')
 
         try:
-            self._edit(text_format=self.text_format, text=body)
+            headers, body, format = self.handleText(text=body)
+            safety_belt = headers.get('SafetyBelt', '') 
+            self.setMetadata(headers)
+            self._edit(text=body, safety_belt=safety_belt)
         except 'EditingConflict', msg:
             # XXX Can we get an error msg through?  Should we be raising an
             #     exception, to be handled in the FTP mechanism?  Inquiring
@@ -369,12 +367,13 @@
             return RESPONSE
 
         RESPONSE.setStatus(204)
+        self.reindexObject()
         return RESPONSE
 
     _htmlsrc = (
         '<html>\n <head>\n'
         ' <title>%(title)s</title>\n'
-        '%(metatags)s\n'
+       '%(metatags)s\n'
         ' </head>\n'
         ' <body>\n%(body)s\n </body>\n'
         '</html>\n'


=== CMF/CMFDefault/DublinCore.py 1.14 => 1.15 ===
         self.setLanguage( language )
         self.setRights( rights )
-        self.reindexObject()
 
     security.declareProtected( CMFCorePermissions.ModifyPortalContent
                              , 'manage_metadata' )
@@ -419,4 +418,5 @@
                      , language=language
                      , rights=rights
                      )
+        self.reindexObject()
 InitializeClass(DefaultDublinCoreImpl)


=== CMF/CMFDefault/NewsItem.py 1.13 => 1.14 ===
     security = ClassSecurityInfo()
 
-    def _edit( self, text, description=None, text_format=None ):
+    security.declareProtected( CMFCorePermissions.ModifyPortalContent, 'edit' )
+    def edit( self, text, description=None, text_format=None ):
         """
             Edit the News Item
         """
@@ -94,10 +95,7 @@
             text_format = getattr(self, 'text_format', 'html')
         if description is not None:
             self.setDescription( description )
-        Document._edit( self, text_format, text )
-
-    security.declareProtected( CMFCorePermissions.ModifyPortalContent, 'edit' )
-    edit = WorkflowAction( _edit )
+        Document.edit( self, text_format, text )
 
 
 Globals.InitializeClass( NewsItem )