[Zope3-Users] Re: There aren't IDict widget ?

KLEIN Stéphane klein.stephane at gmail.com
Fri Sep 29 04:20:01 EDT 2006


2006/9/29, KLEIN Stéphane <klein.stephane at gmail.com>:
> 2006/9/29, KLEIN Stéphane <klein.stephane at gmail.com>:
> > Hello,
> >
> > in one content component I've switch from IList to IDict schema and I
> > note than IDict widget don't exist. It's normal ? if yes, why ?
>
> I see that : http://mail.zope.org/pipermail/zope3-users/2006-June/003720.html
>

In mail http://mail.zope.org/pipermail/zope3-users/2006-June/003720.html
I don't know where put the last part :

from zope.schema.interfaces import WrongContainedType, ValidationError
from zope.schema import Dict
from zope.schema._field import AbstractCollection

def _validate_dict(value_type,key_type, value, errors=None):
	if errors is None:
		errors=[]
	if value_type is None:
		return errors
	if key_type is None:
		return errors
	
	for (key,vl) in value.items():
		try:
			key_type.validate(key)
		except ValidationError, error:
			errors.append(error)
		try:
			value_type.validate(vl)
		except ValidationError, error:
			errors.append(error)
	return errors

class FixedDict(Dict,AbstractCollection):
	"""We have to fix the bind-method of Dict"""
	def bind(self, object):
		clone=AbstractCollection.bind(self,object)
		if clone.key_type is not None:
			clone.key_type = clone.key_type.bind(object)
		return clone

	def _validate(self,value):
		errors=_validate_dict(self.value_type,self.key_type,value)
		if len(errors) > 0:
			raise WrongContainedType(errors)

First part is in browser/configure.zcml
Second part is in browser/widgets.py

But I don't know where put the last part.

Thanks four your help,
Stéphane


More information about the Zope3-users mailing list