[z3-five] can't import an interface into a page template

Florent Guillaume fg at nuxeo.com
Wed Nov 17 16:47:22 MET 2004


Tim Hicks wrote:
> Martijn Faassen said:
> 
>>Tim Hicks wrote:
>>
>>>I'm trying to get hold of an interface (of the zope3 variety) from a zpt
>>>so that I can adapt to it. So, my zpt has::
>>>
>>>  <tal:dummy define="IMessageFlags
>>>modules/Products.atemail.interfaces.IMessageFlags">
>>>
>>Typically I'd say that isn't the business of a page template at all and
>>that such adaptation should take place in Python code. Add a class to
>>your template and create a method that can do the adaptation for you.
>>
>>As to importing stuff into Five zpts; security is turned off so this
>>should Just Work without any Zope 2 security magic. However, I've never
>>tried, so I don't even know what the syntax should be. :)
> 
> 
> 
> Ok, I'm a little further along with this, but have hit another problem.
> 
> I fixed the import problem by having a look at the source for allow_module
> and allow_class.  I was using them wrong.  I now have::
> 
>   import interfaces
>   allow_module('Products.atemail.interfaces')
>   allow_class(interfaces.IMessageFlags)
> 
> And I the following lines in my zpt work::
> 
>   define="ifaces modules/Products.atemail.interfaces;
>           flagstore python:ifaces.IMessageFlags(here);"
> 
> The problem now is that the security machinery blocks me from calling any
> methods on flagstore.
> 
> I thought it was because I had no security (.declareProtected() etc)
> declared on my adapter and that the adapter did not inherit from Implicit.
>  That doesn't quite appear to be the problem as adding that stuff didn't
> fix things.
> 
> I see the following error when I try to call flagstore.setFlag('\\Seen')::
> 
>   File
> "/home/tim/zope/2.8instance/Products/VerboseSecurity/VerboseSecurityPolicy.py",
> line 151, in validate
>     raise Unauthorized(info)
> Unauthorized: The container has no security assertions.  Access to
> 'setFlag' of (Products.atemail.flags.FlagStorage object at 0x41c5034c)
> denied.
> 
> 
> I have a feeling this is because despite having Implicit as a base class,
> my adapter doesn't have an acquisition path back to the zope root object. 

Probably. You could try to have your adapter for IMessageFlags return a 
wrapped version of the object if you can get hold of some persistent 
object under the appropriate user folder. This could work:
   root = Zope.app()
   # or any suitable persistent object you may have lying around
   return flagstorage.__of__(root)
FlagStorage has to inherit from Implicit for this to work.

Or you could try for FlagStorage to directly have a security assertion 
like setDefaultAccess('allow').

Florent


> So, I tried adding the following to the adapter to somehow get hold of
> context's acquisition path::
> 
> def __getattr__(self, name):
>     """ """
>     return self.context.__getattr__(name)
> 
> 
> But that just gives me a runtimeerror when I try to view the zpt::
> 
>   RuntimeError: FS Page Template base_view has errors:
> exceptions.RuntimeError.<br>&lt;pre&gt;maximum recursion depth
> exceeded&lt;/pre&gt;
> 
> I think you need special zen to make __getattr__ work with acquisition. 
> Anyone got any?
> 
> 
> tim
> _______________________________________________
> z3-five mailing list
> z3-five at codespeak.net
> http://codespeak.net/mailman/listinfo/z3-five


-- 
Florent Guillaume, Nuxeo (Paris, France)   CTO, Director of R&D
+33 1 40 33 71 59   http://nuxeo.com   fg at nuxeo.com


More information about the z3-five mailing list