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

Tim Hicks tim at sitefusion.co.uk
Wed Nov 17 16:37:14 MET 2004


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. 
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


More information about the z3-five mailing list