[Zope3-Users] Setting custom content type when publishing a resource

FB fbo2 at gmx.net
Wed Oct 18 01:18:03 EDT 2006


Hi,

On Wed, Oct 18, 2006 at 12:45:50PM +1300, Andrew Groom wrote:
> FB wrote:
> >Hi,
> >On Tue, Oct 17, 2006 at 12:53:48PM +1300, Andrew Groom wrote:
> >>Hi All,
> >>
> >>I want to do something that feels like it should be really simple: set a
> >>specific content type when a particular resource is published (a Firefox
> >>extension, a binary .xpi file if it helps). Any ideas how I could do
> >>that ?

[snip]

> >You should do this in the __call__() method. This is the default view of an
> >advanced IFile implementation of mine:
> >class AutoFileView(BrowserView):
> >   def __call__(self):
> >      self.request.response.setHeader('Content-Type',
> >                                            self.context.contentType)
> >      self.request.response.setHeader('Content-Length',
> >                                            self.context.getSize())
> >      return self.context.data
> 
> Thanks, Frank. The bit I'm missing now is the ZCML to hook it all together. Do I use a 
> browser:resource ? If you could give me an example, that'd be great.

No - it's a simple BrowserView. Just use a standard-page-statement:

<browser:page name="blahblah.html"
   class=".views.AutoFileView"
   permission="zope.View"
/>

BTW: browser:resource is used for 100% static content (CSS-files, icons, images, ...).

Regards,

Frank


More information about the Zope3-users mailing list