[Zope-dev] z3c.form: Need to register SimpleFieldValidator in local site - how?
Hermann Himmelbauer
dusty at qwer.tk
Wed Sep 30 03:19:56 EDT 2009
Hi,
I currently have the following simple validator:
--------------- snip --------------
class ActEmailValidator(SimpleFieldValidator):
"""Validates ACT E-Mail Addresses for customers"""
def validate(self, value):
super(ActEmailValidator, self).validate(value)
if getattr(getSite(), 'bank_specifics', None) == u'act':
if not re.match(r'^.+?@[0-9]+?.uebungsfirmen.at$', value):
raise NotValidActEmail
WidgetValidatorDiscriminators(ActEmailValidator,
context = ICustomer,
field = IFpFlat['email'])
--------------- snip -----------------
Normally, I simple did a "provideAdapter(ActEmailValidator)", which registered
the above adapter in the global site registry.
Unfortunately, this adapter should not be global, instead I need it
site-specific. Therefore I tried the following, as I do with various
utilities:
sm = mySite.getSiteManager()
sm.registerAdapter(ActEmailValidator)
This does not work and generates the following traceback:
------------ snip -------------
File "/home/dusty/prog/bsp/buildout/eggs/ZODB3-3.8.1-py2.4-linux-x86_64.egg/ZODB/serialize.py",
line 416, in _dump
self._p.dump(state)
PicklingError: Can't pickle <InterfaceClass
z3c.form.util.IGeneratedForObject_43371984>: attribute lookup
z3c.form.util.IGeneratedForObject_43371984 failed
------------- snip ------------
From this point I'm stuck - does somebody know what to do here?
I yesterday thought z3c.baseregistry could help, but it seems that it would
not, as I need this registration persistent and not during Zope startup only.
It should be possible to add such sites during runtime, whereas their
configuration (and registration of this adapter) has to be persistent.
Any hints?
Best Regards,
Hermann
--
hermann at qwer.tk
GPG key ID: 299893C7 (on keyservers)
FP: 0124 2584 8809 EF2A DBF9 4902 64B4 D16B 2998 93C7
More information about the Zope-Dev
mailing list