[CMF-checkins] SVN: CMF/branches/tseaver-viewification/CMFDefault/
Do a parallel implementation for link edit view using
Yuppie's pattern.
Tres Seaver
tseaver at palladion.com
Sat Nov 19 13:51:52 EST 2005
Log message for revision 40250:
Do a parallel implementation for link edit view using Yuppie's pattern.
Changed:
U CMF/branches/tseaver-viewification/CMFDefault/browser/configure.zcml
U CMF/branches/tseaver-viewification/CMFDefault/browser/linkviews.py
A CMF/branches/tseaver-viewification/CMFDefault/browser/templates/link_edit.pt
U CMF/branches/tseaver-viewification/CMFDefault/configure.zcml
-=-
Modified: CMF/branches/tseaver-viewification/CMFDefault/browser/configure.zcml
===================================================================
--- CMF/branches/tseaver-viewification/CMFDefault/browser/configure.zcml 2005-11-19 17:53:07 UTC (rev 40249)
+++ CMF/branches/tseaver-viewification/CMFDefault/browser/configure.zcml 2005-11-19 18:51:52 UTC (rev 40250)
@@ -49,6 +49,15 @@
/>
<browser:page
+ for="Products.CMFDefault.interfaces.IMutableLink"
+ name="link_edit_form"
+ class=".linkviews.LinkEditView"
+ template="templates/link_edit.pt"
+ permission="cmf.ModifyPortalContent"
+ layer="cmf"
+ />
+
+ <browser:page
for="Products.CMFDefault.interfaces.IMutableDocument"
name="document_edit_form"
class=".documentviews.DocumentEditView"
Modified: CMF/branches/tseaver-viewification/CMFDefault/browser/linkviews.py
===================================================================
--- CMF/branches/tseaver-viewification/CMFDefault/browser/linkviews.py 2005-11-19 17:53:07 UTC (rev 40249)
+++ CMF/branches/tseaver-viewification/CMFDefault/browser/linkviews.py 2005-11-19 18:51:52 UTC (rev 40250)
@@ -133,3 +133,77 @@
InitializeClass(LinkEditingView)
+#
+# XXX: Try out Yuppie's style here
+#
+import urlparse
+
+from Products.CMFDefault.exceptions import EditingConflict
+from Products.CMFDefault.exceptions import ResourceLockedError
+from Products.CMFDefault.utils import MessageID as _
+
+from utils import FormViewBase
+
+class IllegalURL(ValueError):
+ pass
+
+class LinkEditView(FormViewBase):
+
+ """ Edit view for IMutableDocument.
+ """
+
+ # XXX: _BUTTONS should become configurable
+ _BUTTONS = ({'name': 'change',
+ 'value': _(u'Change'),
+ 'transform': ('validateURL', 'update'),
+ 'redirect': ('context', 'object/edit'),
+ },
+ {'name': 'change_and_view',
+ 'value': _(u'Change and View'),
+ 'transform': ('validateURL', 'update'),
+ 'redirect': ('context', 'object/view'),
+ },
+ )
+
+ def remote_url(self):
+ if 'remote_url' in self.request.form:
+ return self.request['remote_url']
+ else:
+ return self.context.remote_url
+
+ def validateURL(self, remote_url='', **kw):
+ try:
+ remote_url = self._normalizeURL(remote_url)
+ except IllegalURL, errmsg:
+ return self.setStatus(False, errmsg)
+ else:
+ return self.setStatus(True, remote_url=remote_url)
+
+ def _normalizeURL(self, remote_url):
+ tokens = urlparse.urlparse( remote_url, 'http' )
+ if tokens[0] == 'http':
+ if tokens[1]:
+ # We have a nethost. All is well.
+ url = urlparse.urlunparse(tokens)
+ elif tokens[2:] == ('', '', '', ''):
+ # Empty URL
+ url = ''
+ else:
+ # Relative URL, keep it that way, without http:
+ tokens = ('', '') + tokens[2:]
+ url = urlparse.urlunparse(tokens)
+ else:
+ # Other scheme, keep original
+ url = urlparse.urlunparse(tokens)
+ return url
+
+ def update(self, remote_url, **kw):
+ context = self.context
+ if remote_url != context.remote_url:
+ try:
+ context.remote_url = remote_url
+ return self.setStatus(True, _(u'Link changed.'))
+ except (ResourceLockedError, EditingConflict), errmsg:
+ return self.setStatus(False, errmsg)
+ else:
+ return self.setStatus(False, _(u'Nothing to change.'))
Added: CMF/branches/tseaver-viewification/CMFDefault/browser/templates/link_edit.pt
===================================================================
--- CMF/branches/tseaver-viewification/CMFDefault/browser/templates/link_edit.pt 2005-11-19 17:53:07 UTC (rev 40249)
+++ CMF/branches/tseaver-viewification/CMFDefault/browser/templates/link_edit.pt 2005-11-19 18:51:52 UTC (rev 40250)
@@ -0,0 +1,39 @@
+<html metal:use-macro="context/@@standard_macros/page">
+<body>
+
+<metal:slot metal:fill-slot="header" i18n:domain="cmf_default">
+<h1 i18n:translate="">Edit: <tal:span
+ tal:content="context/Title" i18n:name="obj_title">Title</tal:span></h1>
+</metal:slot>
+
+<metal:slot metal:fill-slot="body" i18n:domain="cmf_default">
+<div class="Desktop">
+
+<form action="link_edit_form" method="post"
+ tal:attributes="action request/ACTUAL_URL">
+<table class="FormLayout">
+ <tr>
+ <th i18n:translate="">Title</th>
+ <td tal:content="context/Title">Title</td>
+ </tr>
+ <tr>
+ <th i18n:translate="">URL</th>
+ <td>
+ <input type="text" name="remote_url" value=""
+ tal:attributes="value view/remote_url" />
+ </td>
+ </tr>
+ <tr>
+ <td> </td>
+ <td>
+ <metal:macro metal:use-macro="context/@@form_widget/buttons" />
+ </td>
+ </tr>
+</table>
+</form>
+
+</div>
+</metal:slot>
+
+</body>
+</html>
Property changes on: CMF/branches/tseaver-viewification/CMFDefault/browser/templates/link_edit.pt
___________________________________________________________________
Name: svn:eol-style
+ native
Modified: CMF/branches/tseaver-viewification/CMFDefault/configure.zcml
===================================================================
--- CMF/branches/tseaver-viewification/CMFDefault/configure.zcml 2005-11-19 17:53:07 UTC (rev 40249)
+++ CMF/branches/tseaver-viewification/CMFDefault/configure.zcml 2005-11-19 18:51:52 UTC (rev 40250)
@@ -14,12 +14,12 @@
<!-- XXX: Setting this is required to make the views accessible TTW, but it
breaks tests for now. 2005/10/21, TS
+ -->
<five:traversable
class="Products.CMFDefault.Document.Document"
/>
<five:traversable
class="Products.CMFDefault.Link.Link"
/>
- -->
</configure>
More information about the CMF-checkins
mailing list