Hi Hermann

> Betreff: [Zope-dev] z3c.form: Need to register 
> SimpleFieldValidator in localsite - how?
> 
> 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-x8
> 6_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?

I guess this adapter is persistent (local) but not global
because during startup there is no site involved.

There is no way to have a local adapter involved for global schemas.

If there is no global validation druing startup, and you need a 
local site validation then it's fine to use the baseregistry.
but take care you can't use the adapter during adding the site
itself. Then the adapter is only available if the site is added.
Not during adding.


Regards
Roger Ineichen

> Best Regards,
> Hermann
> 
> --
> herm...@qwer.tk
> GPG key ID: 299893C7 (on keyservers)
> FP: 0124 2584 8809 EF2A DBF9  4902 64B4 D16B 2998 93C7 
> _______________________________________________
> Zope-Dev maillist  -  Zope-Dev@zope.org
> https://mail.zope.org/mailman/listinfo/zope-dev
> **  No cross posts or HTML encoding!  ** (Related lists -  
> https://mail.zope.org/mailman/listinfo/zope-announce
>  https://mail.zope.org/mailman/listinfo/zope )
> 

_______________________________________________
Zope-Dev maillist  -  Zope-Dev@zope.org
https://mail.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 https://mail.zope.org/mailman/listinfo/zope-announce
 https://mail.zope.org/mailman/listinfo/zope )

Reply via email to