[CMF-checkins] CVS: CMF/CMFDefault/skins/content - document_edit.py:1.6 metadata_edit.py:1.5 newsitem_edit.py:1.6

Yvo Schubbe schubbe at web.de
Thu Sep 25 07:36:50 EDT 2003


Update of /cvs-repository/CMF/CMFDefault/skins/content
In directory cvs.zope.org:/tmp/cvs-serv2764/CMFDefault/skins/content

Modified Files:
	document_edit.py metadata_edit.py newsitem_edit.py 
Log Message:
replaced bare excepts in skin scripts and removed NoWL cruft:
- added CMFResourceLockedError and IllegalHTML to CMFCoreExceptions.py
- removed usage of NoWL, updated ResourceLockedError imports
- using CMFCoreExceptions for more specific except statements in scripts
- using urlencode to encode error messages


=== CMF/CMFDefault/skins/content/document_edit.py 1.5 => 1.6 ===
--- CMF/CMFDefault/skins/content/document_edit.py:1.5	Thu Mar  6 05:51:03 2003
+++ CMF/CMFDefault/skins/content/document_edit.py	Thu Sep 25 07:36:49 2003
@@ -1,29 +1,30 @@
 ## Script (Python) "document_edit"
 ##parameters=text_format, text, file='', SafetyBelt='', change_and_view=''
 ##title=Edit a document
+##
+from Products.CMFCore.CMFCoreExceptions import CMFResourceLockedError
+from Products.CMFCore.CMFCoreExceptions import IllegalHTML
+from Products.CMFDefault.utils import scrubHTML
+from Products.PythonScripts.standard import urlencode
+
 try:
-    from Products.CMFDefault.utils import scrubHTML
     text = scrubHTML( text ) # Strip Javascript, etc.
     context.edit( text_format
                 , text
                 , file
                 , safety_belt=SafetyBelt
                 )
-    qst='portal_status_message=Document+changed.'
-
+except (CMFResourceLockedError, 'EditingConflict', IllegalHTML), msg:
+    message = msg
+    action_id = 'edit'
+else:
+    message = 'Document changed.'
     if change_and_view:
-        target_action = context.getTypeInfo().getActionById( 'view' )
+        action_id = 'view'
     else:
-        target_action = context.getTypeInfo().getActionById( 'edit' )
+        action_id = 'edit'
 
-    context.REQUEST.RESPONSE.redirect( '%s/%s?%s' % ( context.absolute_url()
-                                                , target_action
-                                                , qst
-                                                ) )
-except Exception, msg:
-    target_action = context.getTypeInfo().getActionById( 'edit' )
-    context.REQUEST.RESPONSE.redirect(
-        '%s/%s?portal_status_message=%s' % ( context.absolute_url()
-                                           , target_action
-                                           , msg
-                                           ) )
+target = '%s/%s' % ( context.absolute_url(),
+                     context.getTypeInfo().getActionById(action_id) )
+query = urlencode( {'portal_status_message': message} )
+context.REQUEST.RESPONSE.redirect( '%s?%s' % (target, query) )


=== CMF/CMFDefault/skins/content/metadata_edit.py 1.4 => 1.5 ===
--- CMF/CMFDefault/skins/content/metadata_edit.py:1.4	Tue Dec  4 14:04:20 2001
+++ CMF/CMFDefault/skins/content/metadata_edit.py	Thu Sep 25 07:36:49 2003
@@ -1,6 +1,11 @@
 ## Script (Python) "metadata_edit"
+##parameters=allowDiscussion=None, title=None, subject=None, description=None, contributors=None, effective_date=None, expiration_date=None, format=None, language=None, rights=None, change_and_edit='', change_and_view=''
 ##title=Update Content Metadata
-##parameters=allowDiscussion=None,title=None,subject=None,description=None,contributors=None,effective_date=None,expiration_date=None,format=None,language=None,rights=None
+##
+from Products.CMFCore.CMFCoreExceptions import CMFResourceLockedError
+from Products.CMFCore.utils import getToolByName
+from Products.PythonScripts.standard import urlencode
+dtool = getToolByName(script, 'portal_discussion')
 
 def tuplify( value ):
 
@@ -41,9 +46,9 @@
 if rights is None:
     rights = context.Rights()
 
-context.portal_discussion.overrideDiscussionFor(context, allowDiscussion)
+dtool.overrideDiscussionFor(context, allowDiscussion)
 
-try:  
+try:
     context.editMetadata( title=title
                         , description=description
                         , subject=subject
@@ -54,21 +59,19 @@
                         , language=language
                         , rights=rights
                         )
-    if context.REQUEST.get( 'change_and_edit', 0 ):
+except CMFResourceLockedError, msg:
+    message = msg
+    action_id = 'metadata'
+else:
+    message = 'Metadata changed.'
+    if change_and_edit:
         action_id = 'edit'
-    elif context.REQUEST.get( 'change_and_view', 0 ):
+    elif change_and_view:
         action_id = 'view'
     else:
         action_id = 'metadata'
 
-    action_path = context.getTypeInfo().getActionById( action_id )
-    context.REQUEST['RESPONSE'].redirect(
-              '%s/%s?portal_status_message=Metadata+changed.'
-                % ( context.absolute_url(), action_path ) )
-except Exception, msg:
-    target_action = context.getTypeInfo().getActionById( 'metadata' )
-    context.REQUEST.RESPONSE.redirect('%s/%s?portal_status_message=%s' % (
-                                                                          context.absolute_url()
-                                                                        , target_action
-                                                                        , msg
-                                                                         ))
+target = '%s/%s' % ( context.absolute_url(),
+                     context.getTypeInfo().getActionById(action_id) )
+query = urlencode( {'portal_status_message': message} )
+context.REQUEST.RESPONSE.redirect( '%s?%s' % (target, query) )


=== CMF/CMFDefault/skins/content/newsitem_edit.py 1.5 => 1.6 ===
--- CMF/CMFDefault/skins/content/newsitem_edit.py:1.5	Thu Mar  6 05:52:33 2003
+++ CMF/CMFDefault/skins/content/newsitem_edit.py	Thu Sep 25 07:36:49 2003
@@ -1,28 +1,28 @@
 ## Script (Python) "newsitem_edit"
 ##parameters=text, description, text_format=None, change_and_view=''
 ##title=Edit a news item
+##
+from Products.CMFCore.CMFCoreExceptions import CMFResourceLockedError
+from Products.CMFCore.CMFCoreExceptions import IllegalHTML
+from Products.CMFDefault.utils import scrubHTML
+from Products.PythonScripts.standard import urlencode
+
 try:
-    from Products.CMFDefault.utils import scrubHTML
     text = scrubHTML( text ) # Strip Javascript, etc.
     description = scrubHTML( description )
- 
-    context.edit(text=text, description=description, text_format=text_format)
-
-    qst='portal_status_message=News+Item+changed.'
 
+    context.edit(text=text, description=description, text_format=text_format)
+except (CMFResourceLockedError, IllegalHTML), msg:
+    message = msg
+    action_id = 'edit'
+else:
+    message = 'News Item changed.'
     if change_and_view:
-        target_action = context.getTypeInfo().getActionById( 'view' )
+        action_id = 'view'
     else:
-        target_action = context.getTypeInfo().getActionById( 'edit' )
+        action_id = 'edit'
 
-    context.REQUEST.RESPONSE.redirect( '%s/%s?%s' % ( context.absolute_url()
-                                                    , target_action
-                                                    , qst
-                                                    ) )
-except Exception, msg:
-    target_action = context.getTypeInfo().getActionById( 'edit' )
-    context.REQUEST.RESPONSE.redirect(
-        '%s/%s?portal_status_message=%s' % ( context.absolute_url()
-                                           , target_action
-                                           , msg
-                                           ) )
+target = '%s/%s' % ( context.absolute_url(),
+                     context.getTypeInfo().getActionById(action_id) )
+query = urlencode( {'portal_status_message': message} )
+context.REQUEST.RESPONSE.redirect( '%s?%s' % (target, query) )




More information about the CMF-checkins mailing list