[Zope] Re: Product function with extension

Tres Seaver tseaver at palladion.com
Sun Apr 8 19:14:09 EDT 2007


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Gaël Le Mignot wrote:
> Hello Garito!
> 
> Sun, 8 Apr 2007 16:48:14 +0200, you wrote: 
> 
>  > Hi!!
>  > I have a method in my product called freemind wich generate the xml to the
>  > freemind applet but on this applet is mandatory to use the .mm extension
> 
>  > Is possible to create a product function with extension? (in this case will
>  > be something like freemind.mm)
> 
> You could do it with a dirty setattr(self, "myfunction.mm", self.myfunction).
> 
> But I would say the cleanest way is to use the Content-Disposition  HTTP header:
> 
>          Content-Disposition: attachment; filename=myfunction.mm
> 
> (with REQUEST.RESPONSE.setHeader).
> 
> See http://www.ietf.org/rfc/rfc1806.txt for more information on it.
> 

You could also register a browser view which uses your method. E.g.,
to implement the view::

   # Produts/foo/browser.py
   from Products.Five import BrowserView
   class FreemindView(BrowserView):
       def __call__(self, *args, **kw):
           self.request.RESPONSE.setHeader('Content-Type', 'text/xml')
           return self.context.freemind()

and then register the view

  <!-- Products/foo/configure.zcml -->
  <configure xmlns="http://namespaces.zope.org/zope"
             xmlns:browser="http://namespaces.zope.org/browser">

    <browser:page
       for=".interfaces.IFreemindProvider"
       name="freemind.mm"
       class=".browser.FreemindView"
       permission="zope.Public"
       />

The registration assumes that your content class implements an
'IFreemindProvider' view, which might be defined as:

  # Products/foo/interfaces.py
  from zope.interface import Interface
  class IFreemindProvider(Interface):
      """ Document it here.
      """
      def freemind():
          """ Document the method here.
          """

Your content class would then declare that it implements it, e.g.:

  # Products/foo/content.py
  from zope.interface import implements
  from Products.foo.interfaces import IFreemindProvider

  class FooContent(...):
      implements(IFreemindProvider)
      ....


Once set up this way, assuming that yo have a FooContext instance with
the URL, 'http://example.com/path/to/foo', then you could point the
browser to 'http://example.com/path/to/foo/freemind.mm' to get the XML.



Tres.
- --
===================================================================
Tres Seaver          +1 540-429-0999          tseaver at palladion.com
Palladion Software   "Excellence by Design"    http://palladion.com
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2.2 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFGGXdB+gerLs4ltQ4RAjlAAKCeXBZIYWcL1bHM6vjmnaEzznGvSQCeNCld
qCeaE8441MRetKfmNwrhnP0=
=Uzxy
-----END PGP SIGNATURE-----



More information about the Zope mailing list