[Checkins] SVN: z3c.relationfield/trunk/src/z3c/relationfield/ Cut out widget code, this moved to z3c.relationfieldui.

Martijn Faassen faassen at infrae.com
Fri Oct 17 11:59:56 EDT 2008


Log message for revision 92316:
  Cut out widget code, this moved to z3c.relationfieldui.
  

Changed:
  U   z3c.relationfield/trunk/src/z3c/relationfield/README.txt
  U   z3c.relationfield/trunk/src/z3c/relationfield/__init__.py
  D   z3c.relationfield/trunk/src/z3c/relationfield/widget.py

-=-
Modified: z3c.relationfield/trunk/src/z3c/relationfield/README.txt
===================================================================
--- z3c.relationfield/trunk/src/z3c/relationfield/README.txt	2008-10-17 15:58:34 UTC (rev 92315)
+++ z3c.relationfield/trunk/src/z3c/relationfield/README.txt	2008-10-17 15:59:56 UTC (rev 92316)
@@ -376,74 +376,3 @@
   >>> after2 = sorted(catalog.findRelations({'to_id': a_id}))
   >>> len(after2) > len(before)
   True
-
-The relation widget
--------------------
-
-The relation widget can be looked up for a relation field. The widget
-will render with a button that can be used to set the
-relation. Pressing this button will show a pop up window. The URL
-implementing the popup window is defined on a special view that needs
-to be available on the context object (that the relation is defined
-on). This view must be named "explorerurl". We'll provide one here::
-
-  >>> from zope.interface import Interface
-  >>> class ExplorerUrl(grok.View):
-  ...   grok.context(Interface)
-  ...   def render(self):
-  ...      return 'http://grok.zope.org'
-
-XXX in order to grok a view in the tests we need to supply the
-``BuiltinModuleInfo`` class with a ``package_dotted_name`` attribute.
-This should be fixed in Martian::
-
-  >>> from martian.scan import BuiltinModuleInfo
-  >>> BuiltinModuleInfo.package_dotted_name = 'foo'
-
-Now we can Grok the view::
-
-  >>> grok.testing.grok_component('ExplorerUrl', ExplorerUrl)
-  True
-
-Let's take a look at the relation widget now::
-
-  >>> from zope.publisher.browser import TestRequest
-  >>> from z3c.relationfield import RelationWidget
-  >>> request = TestRequest()
-  >>> widget = RelationWidget(IItem['rel'], request)
-  >>> print widget()
-  <input class="textType" id="field.rel" name="field.rel" size="20" type="text" value=""  /><input class="buttonType" onclick="Z3C.relation.popup(this.previousSibling, 'http://grok.zope.org')" type="button" value="get relation" />
-
-Relation display widget
------------------------
-
-The display widget for relation will render a URL to the object it relates
-to. What this URL will be exactly can be controlled by defining a view
-on the object called "relationurl". Without such a view, the display
-widget will link directly to the object::
-
-  >>> from z3c.relationfield import RelationDisplayWidget
-  >>> widget = RelationDisplayWidget(IItem['rel'], request)
-
-We have to set the widget up with some data::
-
-  >>> widget._data = rel 
-
-The widget will point to the plain URL of ``rel``'s ``to_object``::
-
-  >>> print widget()
-  <a href="http://127.0.0.1/root/a">a</a>
-
-Now we register a special ``relationurl`` view::
-
-  >>> class RelationUrl(grok.View):
-  ...   grok.context(Interface)
-  ...   def render(self):
-  ...      return self.url('edit')
-  >>> grok.testing.grok_component('RelationUrl', RelationUrl)
-  True
-
-We should now see a link postfixed with ``/edit``::
-
-  >>> print widget()
-  <a href="http://127.0.0.1/root/a/edit">a</a>

Modified: z3c.relationfield/trunk/src/z3c/relationfield/__init__.py
===================================================================
--- z3c.relationfield/trunk/src/z3c/relationfield/__init__.py	2008-10-17 15:58:34 UTC (rev 92315)
+++ z3c.relationfield/trunk/src/z3c/relationfield/__init__.py	2008-10-17 15:59:56 UTC (rev 92316)
@@ -2,4 +2,3 @@
 from z3c.relationfield.index import RelationCatalog
 from z3c.relationfield.schema import Relation
 from z3c.relationfield.event import realize_relations
-from z3c.relationfield.widget import RelationWidget, RelationDisplayWidget

Deleted: z3c.relationfield/trunk/src/z3c/relationfield/widget.py
===================================================================
--- z3c.relationfield/trunk/src/z3c/relationfield/widget.py	2008-10-17 15:58:34 UTC (rev 92315)
+++ z3c.relationfield/trunk/src/z3c/relationfield/widget.py	2008-10-17 15:59:56 UTC (rev 92316)
@@ -1,69 +0,0 @@
-import grokcore.component as grok
-from xml.sax.saxutils import escape
-
-from zope.app.form.interfaces import IInputWidget, IDisplayWidget
-from zope.publisher.interfaces.browser import IBrowserRequest
-from zope.app.form.browser import TextWidget, DisplayWidget
-from zope import component
-from zope.component.interfaces import ComponentLookupError
-from zope.app.form.browser.widget import renderElement
-from zope.traversing.browser import absoluteURL
-from z3c.objpath.interfaces import IObjectPath
-
-from z3c.relationfield.schema import IRelation
-from z3c.relationfield.interfaces import IRelationInfo
-
-class RelationWidget(grok.MultiAdapter, TextWidget):
-    grok.adapts(IRelation, IBrowserRequest)
-    grok.provides(IInputWidget)
-
-    def __call__(self):
-        result = TextWidget.__call__(self)
-        explorer_url = component.getMultiAdapter((self.context.context,
-                                                 self.request),
-                                                 name="explorerurl")()
-        result += renderElement(
-            'input', type='button', value='get relation',
-            onclick="Z3C.relation.popup(this.previousSibling, '%s')" %
-            explorer_url)
-        return result
-    
-    def _toFieldValue(self, input):
-        if not input:
-            return None
-        # convert path to Relation object
-        obj = self.resolve(input)
-        # XXX if obj is none, cannot create path
-        return IRelationInfo(obj).createRelation()
-
-    def _toFormValue(self, value):
-        if value is None:
-            return ''
-        return value.to_path
-
-    def resolve(self, path):
-        object_path = component.getUtility(IObjectPath)
-        return object_path.resolve(path)
-
-
-class RelationDisplayWidget(grok.MultiAdapter, DisplayWidget):
-    grok.adapts(IRelation, IBrowserRequest)
-    grok.provides(IDisplayWidget)
-
-    def __call__(self):
-        if self._renderedValueSet():
-            value = self._data
-        else:
-            value = self.context.default
-        if value == self.context.missing_value:
-            return ""
-        to_object = value.to_object
-        try:
-            to_url = component.getMultiAdapter((to_object, self.request),
-                                               name="relationurl")()
-        except ComponentLookupError:
-            to_url = absoluteURL(to_object, self.request)
-        return '<a href="%s">%s</a>' % (
-            to_url,
-            escape(value.to_path))
-



More information about the Checkins mailing list