[CMF-checkins] SVN: CMF/branches/tseaver-viewification/CMFDefault/browser/ - made sure changes are not lost if there is an error (this is a behavior change compared to the old skin method)

Yvo Schubbe y.2005- at wcm-solutions.de
Mon Oct 24 06:38:37 EDT 2005


Log message for revision 39570:
  - made sure changes are not lost if there is an error (this is a behavior change compared to the old skin method)
  - made more explicit that messages are unicode strings

Changed:
  U   CMF/branches/tseaver-viewification/CMFDefault/browser/documentviews.py
  U   CMF/branches/tseaver-viewification/CMFDefault/browser/templates/document_edit.pt

-=-
Modified: CMF/branches/tseaver-viewification/CMFDefault/browser/documentviews.py
===================================================================
--- CMF/branches/tseaver-viewification/CMFDefault/browser/documentviews.py	2005-10-24 10:38:11 UTC (rev 39569)
+++ CMF/branches/tseaver-viewification/CMFDefault/browser/documentviews.py	2005-10-24 10:38:37 UTC (rev 39570)
@@ -1,3 +1,20 @@
+##############################################################################
+#
+# Copyright (c) 2005 Zope Corporation and Contributors. All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""Browser views for documents.
+
+$Id$
+"""
+
 from Products.CMFDefault.exceptions import EditingConflict
 from Products.CMFDefault.exceptions import IllegalHTML
 from Products.CMFDefault.exceptions import ResourceLockedError
@@ -12,16 +29,34 @@
     """ Edit view for IMutableDocument.
     """
 
-    # XXX: _BUTTONS this should become configurable
+    # XXX: _BUTTONS should become configurable
     _BUTTONS = ({'name': 'change',
-                 'value': _('Change'),
+                 'value': _(u'Change'),
                  'transform': ('validateTextFile', 'validateHTML', 'update'),
                  'redirect': ('context', 'object/edit')},
                 {'name': 'change_and_view',
-                 'value': _('Change and View'),
+                 'value': _(u'Change and View'),
                  'transform': ('validateTextFile', 'validateHTML', 'update'),
                  'redirect': ('context', 'object/view')})
 
+    def SafetyBelt(self):
+        if 'SafetyBelt' in self.request.form:
+            return self.request['SafetyBelt']
+        else:
+            return self.context.SafetyBelt()
+
+    def text_format(self):
+        if 'text_format' in self.request.form:
+            return self.request['text_format']
+        else:
+            return self.context.text_format
+
+    def EditableBody(self):
+        if 'text' in self.request.form:
+            return self.request['text']
+        else:
+            return self.context.EditableBody()
+
     def validateTextFile(self, file='', **kw):
         try:
             upload = file.read()
@@ -46,8 +81,8 @@
         if text_format != context.text_format or text != context.text:
             try:
                 context.edit(text_format, text, safety_belt=SafetyBelt)
-                return self.setStatus(True, _('Document changed.'))
+                return self.setStatus(True, _(u'Document changed.'))
             except (ResourceLockedError, EditingConflict), errmsg:
                 return self.setStatus(False, errmsg)
         else:
-            return self.setStatus(False, _('Nothing to change.'))
+            return self.setStatus(False, _(u'Nothing to change.'))

Modified: CMF/branches/tseaver-viewification/CMFDefault/browser/templates/document_edit.pt
===================================================================
--- CMF/branches/tseaver-viewification/CMFDefault/browser/templates/document_edit.pt	2005-10-24 10:38:11 UTC (rev 39569)
+++ CMF/branches/tseaver-viewification/CMFDefault/browser/templates/document_edit.pt	2005-10-24 10:38:37 UTC (rev 39570)
@@ -12,7 +12,7 @@
 <form action="document_edit_form" method="post" enctype="multipart/form-data"
    tal:attributes="action request/ACTUAL_URL">
  <input type="hidden" name="SafetyBelt" value=""
-        tal:attributes="value context/SafetyBelt" />
+        tal:attributes="value view/SafetyBelt" />
 <table class="FormLayout">
  <tr>
   <th i18n:translate="">Title</th>
@@ -26,14 +26,13 @@
   <th i18n:translate="">Format</th>
   <td>
    <input type="radio" name="text_format" value="structured-text" id="cb_stx"
-      tal:attributes="
-             checked python:path('context/text_format')=='structured-text'" />
+      tal:attributes="checked python:view.text_format()=='structured-text'" />
    <label for="cb_stx" i18n:translate="">structured-text</label>
    <input type="radio" name="text_format" value="plain" id="cb_plain"
-      tal:attributes="checked python:path('context/text_format')=='plain'" />
+      tal:attributes="checked python:view.text_format()=='plain'" />
    <label for="cb_plain" i18n:translate="">plain text</label>
    <input type="radio" name="text_format" value="html" id="cb_html"
-      tal:attributes="checked python:path('context/text_format')=='html'" />
+      tal:attributes="checked python:view.text_format()=='html'" />
    <label for="cb_html" i18n:translate="">html</label>
   </td>
  </tr>
@@ -47,7 +46,7 @@
   <th class="TextField" i18n:translate="">Edit</th>
   <td class="TextField">
    <textarea name="text:text" rows="20" cols="80" wrap="soft"
-             tal:content="context/EditableBody"></textarea>
+             tal:content="view/EditableBody"></textarea>
   </td>
  </tr>
  <tr>



More information about the CMF-checkins mailing list