[Checkins] SVN: z3c.relationfieldui/trunk/ A lot of cleanups before release.
Martijn Faassen
faassen at infrae.com
Fri Dec 5 14:12:11 EST 2008
Log message for revision 93679:
A lot of cleanups before release.
Changed:
_U z3c.relationfieldui/trunk/
U z3c.relationfieldui/trunk/buildout.cfg
U z3c.relationfieldui/trunk/setup.py
U z3c.relationfieldui/trunk/src/z3c/relationfieldui/README.txt
U z3c.relationfieldui/trunk/src/z3c/relationfieldui/configure.zcml
U z3c.relationfieldui/trunk/src/z3c/relationfieldui/ftests.py
A z3c.relationfieldui/trunk/src/z3c/relationfieldui/resources/
D z3c.relationfieldui/trunk/src/z3c/relationfieldui/static/
U z3c.relationfieldui/trunk/src/z3c/relationfieldui/widget.py
-=-
Property changes on: z3c.relationfieldui/trunk
___________________________________________________________________
Modified: svn:externals
- z3c.relationfield svn://svn.zope.org/repos/main/z3c.relationfield/trunk
+
Modified: z3c.relationfieldui/trunk/buildout.cfg
===================================================================
--- z3c.relationfieldui/trunk/buildout.cfg 2008-12-05 19:09:03 UTC (rev 93678)
+++ z3c.relationfieldui/trunk/buildout.cfg 2008-12-05 19:12:10 UTC (rev 93679)
@@ -1,12 +1,11 @@
[buildout]
-develop = . z3c.relationfield
+develop = .
parts = test
-find-links = http://download.zope.org/distribution/
extends = http://grok.zope.org/releaseinfo/grok-0.14.cfg
versions = versions
[versions]
-lxml = 1.3.6
+lxml = 2.0.9
zope.testing = 3.6.0
[test]
Modified: z3c.relationfieldui/trunk/setup.py
===================================================================
--- z3c.relationfieldui/trunk/setup.py 2008-12-05 19:09:03 UTC (rev 93678)
+++ z3c.relationfieldui/trunk/setup.py 2008-12-05 19:12:10 UTC (rev 93679)
@@ -18,6 +18,11 @@
install_requires=[
'setuptools',
'z3c.relationfield',
+ 'z3c.schema2xml >= 1.0',
+ 'grokcore.component',
+ 'grokcore.view',
+ 'hurry.resource',
+ 'hurry.zoperesource >= 0.3', # for testing
],
entry_points={},
)
Modified: z3c.relationfieldui/trunk/src/z3c/relationfieldui/README.txt
===================================================================
--- z3c.relationfieldui/trunk/src/z3c/relationfieldui/README.txt 2008-12-05 19:09:03 UTC (rev 93678)
+++ z3c.relationfieldui/trunk/src/z3c/relationfieldui/README.txt 2008-12-05 19:12:10 UTC (rev 93679)
@@ -1,26 +1,37 @@
-===================
+*******************
z3c.relationfieldui
-===================
+*******************
-This package implements a widget for relations as defined by
-`z3c.relationfield`_.
+This package implements a ``zope.formlib`` compatible widget for
+relations as defined by `z3c.relationfield`_.
.. `_z3c.relationfield`: http://pypy.python.org/pypi/z3c.relationfield
Setup
------
+=====
-In order to demonstrate our widget, we need to set up a relation field.
+In order to demonstrate our widget, we need to first set up a relation
+field (for the details of this see z3c.relationfield's
+documentation)::
-We first need to grok ftests to make sure we have the right utilities
-registered::
+ >>> from z3c.relationfield import Relation
+ >>> from zope.interface import Interface
+ >>> class IItem(Interface):
+ ... rel = Relation(title=u"Relation")
+ >>> from z3c.relationfield.interfaces import IHasRelations
+ >>> from persistent import Persistent
+ >>> from zope.interface import implements
+ >>> class Item(Persistent):
+ ... implements(IItem, IHasRelations)
+ ... def __init__(self):
+ ... self.rel = None
+ >>> from zope.app.component.site import SiteManagerContainer
+ >>> from zope.app.container.btree import BTreeContainer
+ >>> class TestApp(SiteManagerContainer, BTreeContainer):
+ ... pass
- >>> import grok
- >>> grok.testing.grok('z3c.relationfieldui.ftests')
+Set up the application with the right utilities::
-Let's set up a test application with content in it, including a relation
-from ``b`` to ``a``::
-
>>> root = getRootFolder()['root'] = TestApp()
>>> from zope.app.component.site import LocalSiteManager
>>> root.setSiteManager(LocalSiteManager(root))
@@ -36,6 +47,8 @@
>>> root['catalog'] = catalog = RelationCatalog()
>>> sm.registerUtility(catalog, provided=ICatalog)
+Items ``a`` and ``b`` with a relation from ``b`` to ``a``::
+
>>> root['a'] = Item()
>>> from z3c.relationfield import RelationValue
>>> b = Item()
@@ -49,6 +62,7 @@
We also need to set up a utility that knows how to generate an object
path for a given object, and back::
+ >>> import grokcore.component as grok
>>> from z3c.objpath.interfaces import IObjectPath
>>> class ObjectPath(grok.GlobalUtility):
... grok.provides(IObjectPath)
@@ -56,12 +70,11 @@
... return obj.__name__
... def resolve(self, path):
... return root[path]
-
>>> grok.testing.grok_component('ObjectPath', ObjectPath)
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
@@ -71,18 +84,12 @@
on). This view must be named "explorerurl". We'll provide one here::
>>> from zope.interface import Interface
- >>> class ExplorerUrl(grok.View):
+ >>> import grokcore.view
+ >>> class ExplorerUrl(grokcore.view.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)
@@ -98,7 +105,7 @@
<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
@@ -119,7 +126,7 @@
Now we register a special ``relationurl`` view::
- >>> class RelationUrl(grok.View):
+ >>> class RelationUrl(grokcore.view.View):
... grok.context(Interface)
... def render(self):
... return self.url('edit')
Modified: z3c.relationfieldui/trunk/src/z3c/relationfieldui/configure.zcml
===================================================================
--- z3c.relationfieldui/trunk/src/z3c/relationfieldui/configure.zcml 2008-12-05 19:09:03 UTC (rev 93678)
+++ z3c.relationfieldui/trunk/src/z3c/relationfieldui/configure.zcml 2008-12-05 19:12:10 UTC (rev 93679)
@@ -1,10 +1,18 @@
<configure
xmlns="http://namespaces.zope.org/zope"
- xmlns:grok="http://namespaces.zope.org/grok">
+ xmlns:grok="http://namespaces.zope.org/grok"
+ xmlns:browser="http://namespaces.zope.org/browser">
<include package="grokcore.component" file="meta.zcml" />
+ <include package="grokcore.view" file="meta.zcml" />
+
+ <include package="hurry.zoperesource" />
<include package="z3c.relationfield" />
<grok:grok package="."/>
+
+ <browser:resourceDirectory
+ name="z3c.relationfieldui"
+ directory="resources" />
</configure>
Modified: z3c.relationfieldui/trunk/src/z3c/relationfieldui/ftests.py
===================================================================
--- z3c.relationfieldui/trunk/src/z3c/relationfieldui/ftests.py 2008-12-05 19:09:03 UTC (rev 93678)
+++ z3c.relationfieldui/trunk/src/z3c/relationfieldui/ftests.py 2008-12-05 19:12:10 UTC (rev 93679)
@@ -1,48 +1,19 @@
import unittest
-import grok
-
-from persistent import Persistent
-
-import zope.interface
-from zope.interface import implements
-from zope.app.component.site import SiteManagerContainer
-from zope.app.container.btree import BTreeContainer
-
-from zope.app.intid import IntIds
-from zope.app.intid.interfaces import IIntIds
-
-from zc.relation.interfaces import ICatalog
-
-from z3c.relationfield.interfaces import IHasRelations
-from z3c.relationfield import Relation, RelationCatalog
-
+from zope.app.testing.setup import setUpTestAsModule, tearDownTestAsModule
from zope.app.testing.functional import FunctionalDocFileSuite
-from z3c.relationfield.testing import FunctionalLayer
+from z3c.relationfieldui.testing import FunctionalLayer
-class IItem(zope.interface.Interface):
- """Test fixture used by README.txt
- """
- rel = Relation(title=u"Relation")
+def setUp(test):
+ setUpTestAsModule(test, name='__builtin__')
-class Item(Persistent):
- """Test fixture used by README.txt
- """
- implements(IItem, IHasRelations)
-
- def __init__(self):
- self.rel = None
-
-class TestApp(SiteManagerContainer, BTreeContainer):
- """Test fixture used by README.txt.
- """
- pass
-
def test_suite():
- globs = { 'TestApp': TestApp, 'IItem': IItem, 'Item': Item }
+ globs = {}
readme = FunctionalDocFileSuite(
'README.txt',
globs = globs,
+ setUp=setUp,
+ tearDown=tearDownTestAsModule,
)
readme.layer = FunctionalLayer
return unittest.TestSuite([readme])
Modified: z3c.relationfieldui/trunk/src/z3c/relationfieldui/widget.py
===================================================================
--- z3c.relationfieldui/trunk/src/z3c/relationfieldui/widget.py 2008-12-05 19:09:03 UTC (rev 93678)
+++ z3c.relationfieldui/trunk/src/z3c/relationfieldui/widget.py 2008-12-05 19:12:10 UTC (rev 93679)
@@ -8,11 +8,16 @@
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 hurry.resource import Library, ResourceInclusion
from z3c.relationfield.schema import IRelation
from z3c.relationfield.interfaces import IRelationInfo
+relation_lib = Library('z3c.relationfieldui')
+relation_resource = ResourceInclusion(relation_lib, 'relation.js')
+
class RelationWidget(grok.MultiAdapter, TextWidget):
grok.adapts(IRelation, IBrowserRequest)
grok.provides(IInputWidget)
@@ -26,8 +31,9 @@
'input', type='button', value='get relation',
onclick="Z3C.relation.popup(this.previousSibling, '%s')" %
explorer_url)
+ relation_resource.need()
return result
-
+
def _toFieldValue(self, input):
if not input:
return None
More information about the Checkins
mailing list