[Checkins] SVN: zope3org/trunk/src/zorg/multiform/ moved selection
stuff out of grid form
Bernd Dorn
bernd.dorn at fhv.at
Mon Apr 10 16:37:56 EDT 2006
Log message for revision 66814:
moved selection stuff out of grid form
Changed:
U zope3org/trunk/src/zorg/multiform/gridform.py
A zope3org/trunk/src/zorg/multiform/selection.py
U zope3org/trunk/src/zorg/multiform/tests.py
-=-
Modified: zope3org/trunk/src/zorg/multiform/gridform.py
===================================================================
--- zope3org/trunk/src/zorg/multiform/gridform.py 2006-04-10 20:29:53 UTC (rev 66813)
+++ zope3org/trunk/src/zorg/multiform/gridform.py 2006-04-10 20:37:55 UTC (rev 66814)
@@ -1,10 +1,5 @@
-from interfaces import ISelection,IFormLocation,IGridForm,IGridItemForm
-from zope.schema.fieldproperty import FieldProperty
+from interfaces import IGridForm,IGridItemForm
from zope.interface import implements
-from zope.proxy import ProxyBase, getProxiedObject
-from zope.app.decorator import DecoratorSpecificationDescriptor
-from zope.app.decorator import DecoratedSecurityCheckerDescriptor
-from zope.app.location import location
import multiform
from zope.formlib import namedtemplate
from zope.app.pagetemplate import ViewPageTemplateFile
@@ -17,123 +12,6 @@
ViewPageTemplateFile('griditem.pt'), IGridItemForm)
-class FormLocationSelection(object):
-
- __doc__ = """Form Location-object proxy
-
- This is a non-picklable proxy that can be put around objects that
- implement `ILocation`.
- >>> from zope.publisher.browser import TestRequest
- >>> from zope import interface
- >>> class L(object):
- ... __name__ = u'name'
- >>> l= L()
- >>> class F(object):
- ... request = TestRequest()
- ... context = 1
- ... prefix = u"form.n1"
- >>> f = F()
- >>> p = FormLocationProxy(l, f)
- >>> p = FormLocationSelection(p)
- >>> p.selected
- False
- >>> p.selected = True
- >>> p.selected
- True
- >>> p.selected = False
- >>> p.selected
- False
- """
-
- implements(ISelection)
-
- def __init__(self,context):
- self.context = context
- self.request = context.__form__.request
-
- def _setSelected(self,v):
- key = '_mf_selection.' + self.context.__form__.prefix
- self.request.form[key]=v
-
- def _getSelected(self):
- key = '_mf_selection.' + self.context.__form__.prefix
- return self.request.form.get(key,False)
-
- selected = property(_getSelected ,_setSelected)
-
-
-class FormLocationProxy(ProxyBase):
-
- __doc__ = """Form Location-object proxy
-
- This is a non-picklable proxy that can be put around objects that
- implement `ILocation`.
-
- >>> from zope import interface
- >>> class IMarker(interface.Interface): pass
- >>> class L(object):
- ... x = 1
- >>> l = L()
- >>> interface.directlyProvides(l,IMarker)
- >>> p = FormLocationProxy(l, "Form")
- >>> p.x
- 1
- >>> p.x=2
- >>> p.x
- 2
- >>> l.x
- 2
- >>> p.__form__
- 'Form'
-
- >>> IFormLocation.providedBy(p)
- True
-
- >>> IMarker.providedBy(p)
- True
-
- >>> import pickle
- >>> p2 = pickle.dumps(p)
- Traceback (most recent call last):
- ...
- TypeError: Not picklable
-
- Proxies should get their doc strings from the object they proxy:
-
- >>> p.__doc__ == l.__doc__
- True
-
- """
-
- implements(IFormLocation)
-
- __slots__ = '__form__'
- __safe_for_unpickling__ = True
-
- def __new__(self, ob, form):
- return ProxyBase.__new__(self, ob)
-
- def __init__(self, ob, form):
- ProxyBase.__init__(self, ob)
- self.__form__ = form
-
- def __reduce__(self, proto=None):
- raise TypeError("Not picklable")
-
-
- __doc__ = location.ClassAndInstanceDescr(
- lambda inst: getProxiedObject(inst).__doc__,
- lambda cls, __doc__ = __doc__: __doc__,
- )
-
- __reduce_ex__ = __reduce__
-
- __providedBy__ = DecoratorSpecificationDescriptor()
-
- __Security_checker__ = DecoratedSecurityCheckerDescriptor()
-
-
-
class GridItemFormBase(multiform.ItemFormBase):
implements(IGridItemForm)
template = namedtemplate.NamedTemplate('default')
Added: zope3org/trunk/src/zorg/multiform/selection.py
===================================================================
--- zope3org/trunk/src/zorg/multiform/selection.py 2006-04-10 20:29:53 UTC (rev 66813)
+++ zope3org/trunk/src/zorg/multiform/selection.py 2006-04-10 20:37:55 UTC (rev 66814)
@@ -0,0 +1,122 @@
+from zope.interface import implements
+from interfaces import ISelection,IFormLocation
+from zope.proxy import ProxyBase, getProxiedObject
+from zope.app.decorator import DecoratorSpecificationDescriptor
+from zope.app.decorator import DecoratedSecurityCheckerDescriptor
+from zope.app.location import location
+
+class FormLocationSelection(object):
+
+ __doc__ = """Form Location-object proxy
+
+ This is a non-picklable proxy that can be put around objects that
+ implement `ILocation`.
+ >>> from zope.publisher.browser import TestRequest
+ >>> from zope import interface
+ >>> class L(object):
+ ... __name__ = u'name'
+ >>> l= L()
+ >>> class F(object):
+ ... request = TestRequest()
+ ... context = 1
+ ... prefix = u"form.n1"
+ >>> f = F()
+ >>> p = FormLocationProxy(l, f)
+ >>> p = FormLocationSelection(p)
+ >>> p.selected
+ False
+ >>> p.selected = True
+ >>> p.selected
+ True
+ >>> p.selected = False
+ >>> p.selected
+ False
+ """
+
+ implements(ISelection)
+
+ def __init__(self,context):
+ self.context = context
+
+ def _setSelected(self,v):
+ key = '_mf_selection.' + self.context.__form__.prefix
+ self.context.__form__.request.form[key]=v
+
+ def _getSelected(self):
+ key = '_mf_selection.' + self.context.__form__.prefix
+ return self.context.__form__.request.form.get(key,False)
+
+ selected = property(_getSelected ,_setSelected)
+
+
+class FormLocationProxy(ProxyBase):
+
+ __doc__ = """Form Location-object proxy
+
+ This is a non-picklable proxy that can be put around objects that
+ implement `ILocation`.
+
+ >>> from zope import interface
+ >>> class IMarker(interface.Interface): pass
+ >>> class L(object):
+ ... x = 1
+ >>> l = L()
+ >>> interface.directlyProvides(l,IMarker)
+ >>> p = FormLocationProxy(l, "Form")
+ >>> p.x
+ 1
+ >>> p.x=2
+ >>> p.x
+ 2
+ >>> l.x
+ 2
+ >>> p.__form__
+ 'Form'
+
+ >>> IFormLocation.providedBy(p)
+ True
+
+ >>> IMarker.providedBy(p)
+ True
+
+ >>> import pickle
+ >>> p2 = pickle.dumps(p)
+ Traceback (most recent call last):
+ ...
+ TypeError: Not picklable
+
+ Proxies should get their doc strings from the object they proxy:
+
+ >>> p.__doc__ == l.__doc__
+ True
+
+ """
+
+ implements(IFormLocation)
+
+ __slots__ = '__form__'
+ __safe_for_unpickling__ = True
+
+ def __new__(self, ob, form):
+ return ProxyBase.__new__(self, ob)
+
+ def __init__(self, ob, form):
+ ProxyBase.__init__(self, ob)
+ self.__form__ = form
+
+ def __reduce__(self, proto=None):
+ raise TypeError("Not picklable")
+
+
+ __doc__ = location.ClassAndInstanceDescr(
+ lambda inst: getProxiedObject(inst).__doc__,
+ lambda cls, __doc__ = __doc__: __doc__,
+ )
+
+ __reduce_ex__ = __reduce__
+
+ __providedBy__ = DecoratorSpecificationDescriptor()
+
+ __Security_checker__ = DecoratedSecurityCheckerDescriptor()
+
+
Modified: zope3org/trunk/src/zorg/multiform/tests.py
===================================================================
--- zope3org/trunk/src/zorg/multiform/tests.py 2006-04-10 20:29:53 UTC (rev 66813)
+++ zope3org/trunk/src/zorg/multiform/tests.py 2006-04-10 20:37:55 UTC (rev 66814)
@@ -9,8 +9,8 @@
import zope.app.form.interfaces
import interfaces
import gridform
+import selection
-
def setUp(test):
setup.placefulSetUp()
@@ -57,14 +57,14 @@
zope.app.form.interfaces.IInputWidget,
)
component.provideAdapter(
- gridform.FormLocationProxy,
+ selection.FormLocationProxy,
[zope.app.location.interfaces.ILocation,
zope.formlib.interfaces.IForm
],
interfaces.IFormLocation
)
component.provideAdapter(
- gridform.FormLocationSelection,
+ selection.FormLocationSelection,
[interfaces.IFormLocation],
interfaces.ISelection
)
@@ -82,7 +82,7 @@
return unittest.TestSuite(
(
- DocTestSuite('multiform.gridform',
+ DocTestSuite('multiform.selection',
optionflags=doctest.NORMALIZE_WHITESPACE|doctest.ELLIPSIS,
),
DocFileSuite('README.txt',
More information about the Checkins
mailing list