[CMF-checkins] CVS: CMF/CMFDefault/skins/zpt_content - document_edit.py:1.1 newsitem_edit.py:1.1 validateHTML.py:1.1 validateTextFile.py:1.1 document_edit_control.py:1.4 newsitem_edit_control.py:1.4

Yvo Schubbe y.2004_ at wcm-solutions.de
Tue Jun 1 13:40:58 EDT 2004


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

Modified Files:
	document_edit_control.py newsitem_edit_control.py 
Added Files:
	document_edit.py newsitem_edit.py validateHTML.py 
	validateTextFile.py 
Log Message:
- factored out (again) controllers and validators for document_edit_form / newsitem_edit_form


=== Added File CMF/CMFDefault/skins/zpt_content/document_edit.py ===
## Script (Python) "document_edit"
##parameters=text_format, text, SafetyBelt='', **kw
##title=Edit a document
##
from Products.CMFDefault.exceptions import EditingConflict
from Products.CMFDefault.exceptions import ResourceLockedError

if text_format != context.text_format or text != context.text:
    try:
        context.edit(text_format, text, safety_belt=SafetyBelt)
        return context.setStatus(True, 'Document changed.')
    except (ResourceLockedError, EditingConflict), errmsg:
        return context.setStatus(False, errmsg)
else:
    return context.setStatus(False, 'Nothing to change.')


=== Added File CMF/CMFDefault/skins/zpt_content/newsitem_edit.py ===
## Script (Python) "newsitem_edit"
##parameters=text_format, text, description='', **kw
##title=Edit a news item
##
from Products.CMFDefault.exceptions import ResourceLockedError

if description != context.description or \
        text_format != context.text_format or text != context.text:
    try:
        context.edit(text=text, description=description,
                     text_format=text_format)
        return context.setStatus(True, 'News Item changed.')
    except ResourceLockedError, errmsg:
        return context.setStatus(False, errmsg)
else:
    return context.setStatus(False, 'Nothing to change.')


=== Added File CMF/CMFDefault/skins/zpt_content/validateHTML.py ===
## Script (Python) "validateHTML"
##parameters=text, description='', **kw
##title=
##
from Products.CMFDefault.exceptions import IllegalHTML
from Products.CMFDefault.utils import scrubHTML

try:
    description = scrubHTML(description)
    text = scrubHTML(text)
    return context.setStatus(True, text=text, description=description)
except IllegalHTML, errmsg:
    return context.setStatus(False, errmsg)


=== Added File CMF/CMFDefault/skins/zpt_content/validateTextFile.py ===
## Script (Python) "validateFile"
##parameters=file='', **kw
##title=
##
try:
    upload = file.read()
except AttributeError:
    return context.setStatus(True)
else:
    if upload:
        return context.setStatus(True, text=upload)
    else:
        return context.setStatus(True)


=== CMF/CMFDefault/skins/zpt_content/document_edit_control.py 1.3 => 1.4 ===
--- CMF/CMFDefault/skins/zpt_content/document_edit_control.py:1.3	Thu Apr 29 12:13:19 2004
+++ CMF/CMFDefault/skins/zpt_content/document_edit_control.py	Tue Jun  1 13:40:57 2004
@@ -1,56 +1,20 @@
 ## Script (Python) "document_edit_control"
-##bind container=container
-##bind context=context
-##bind namespace=
-##bind script=script
-##bind subpath=traverse_subpath
-##parameters=text_format='', text='', file='', SafetyBelt='', change='', change_and_view=''
+##parameters=text_format='', text='', file='', SafetyBelt='', change='', change_and_view='', **kw
 ##title=
 ##
-from ZTUtils import make_query
-from Products.CMFDefault.exceptions import EditingConflict
-from Products.CMFDefault.exceptions import IllegalHTML
-from Products.CMFDefault.exceptions import ResourceLockedError
-from Products.CMFDefault.utils import scrubHTML
-
-message = ''
-
-
-if change or change_and_view:
-    ok = 1
-    message = 'Nothing to change.'
-
-    try:
-        upload = file.read()
-    except AttributeError:
-        pass
-    else:
-        if upload:
-            text = upload
-
-    try:
-        text = scrubHTML(text)
-    except IllegalHTML, msg:
-        ok = 0
-        message = msg
-
-    if ok and (text_format != context.text_format or text != context.text):
-        try:
-            context.edit(text_format, text, safety_belt=SafetyBelt)
-        except (ResourceLockedError, EditingConflict), msg:
-            ok = 0
-            message = msg
-        else:
-            message = 'Document changed.'
-
-    if ok and change_and_view:
-        target = context.getActionInfo('object/view')['url']
-        query = make_query(portal_status_message=message)
-        context.REQUEST.RESPONSE.redirect( '%s?%s' % (target, query) )
-        return None
-
-if message:
-    context.REQUEST.set('portal_status_message', message)
+form = context.REQUEST.form
+if change and \
+        context.validateTextFile(**form) and \
+        context.validateHTML(**form) and \
+        context.document_edit(**form) and \
+        context.setRedirect(context, 'object/edit'):
+    return
+elif change_and_view and \
+        context.validateTextFile(**form) and \
+        context.validateHTML(**form) and \
+        context.document_edit(**form) and \
+        context.setRedirect(context, 'object/view'):
+    return
 
 
 control = {}


=== CMF/CMFDefault/skins/zpt_content/newsitem_edit_control.py 1.3 => 1.4 ===
--- CMF/CMFDefault/skins/zpt_content/newsitem_edit_control.py:1.3	Thu Apr 29 12:13:19 2004
+++ CMF/CMFDefault/skins/zpt_content/newsitem_edit_control.py	Tue Jun  1 13:40:57 2004
@@ -1,50 +1,18 @@
 ## Script (Python) "newsitem_edit_control"
-##bind container=container
-##bind context=context
-##bind namespace=
-##bind script=script
-##bind subpath=traverse_subpath
-##parameters=description='', text_format='', text='', change='', change_and_view=''
+##parameters=description='', text_format='', text='', change='', change_and_view='', **kw
 ##title=
 ##
-from ZTUtils import make_query
-from Products.CMFDefault.exceptions import IllegalHTML
-from Products.CMFDefault.exceptions import ResourceLockedError
-from Products.CMFDefault.utils import scrubHTML
-
-message = ''
-
-
-if change or change_and_view:
-    ok = 1
-    message = 'Nothing to change.'
-
-    try:
-        description = scrubHTML(description)
-        text = scrubHTML(text)
-    except IllegalHTML, msg:
-        ok = 0
-        message = msg
-
-    if ok and (description != context.description
-               or text_format != context.text_format or text != context.text):
-        try:
-            context.edit(text=text, description=description,
-                         text_format=text_format)
-        except ResourceLockedError, msg:
-            ok = 0
-            message = msg
-        else:
-            message = 'News Item changed.'
-
-    if ok and change_and_view:
-        target = context.getActionInfo('object/view')['url']
-        query = make_query(portal_status_message=message)
-        context.REQUEST.RESPONSE.redirect( '%s?%s' % (target, query) )
-        return None
-
-if message:
-    context.REQUEST.set('portal_status_message', message)
+form = context.REQUEST.form
+if change and \
+        context.validateHTML(**form) and \
+        context.newsitem_edit(**form) and \
+        context.setRedirect(context, 'object/edit'):
+    return
+elif change_and_view and \
+        context.validateHTML(**form) and \
+        context.newsitem_edit(**form) and \
+        context.setRedirect(context, 'object/view'):
+    return
 
 
 control = {}




More information about the CMF-checkins mailing list