[Zope3-Users] Setting custom content type when publishing a
resource
Andrew Groom
andrew at reurbanise.co.nz
Wed Oct 18 02:58:45 EDT 2006
Hi Frank,
Thanks for the ZCML, but I'm still having problems. Here's what I have
so far:
configure.zcml:
<configure xmlns:browser="http://namespaces.zope.org/browser">
<browser:page
for="*"
name="vortexgdna.xpi"
class=".xpipublisher.XPIPublisherView"
permission="zope.View"/>
</configure>
(It complained if I didn't have the "for" attribute in there, btw)
xpipublisher.py
from zope.app.publisher.browser import BrowserView
class XPIPublisherView (BrowserView):
def __call__(self):
self.request.response.setHeader('Content-Type',
'application/x-xpinstall')
return self.context.data
When I try to access http://(domain)/vortexgdna.xpi, I get:
File "(snip)/xpipublisher.py", line 8, in __call__
return self.context.data
ForbiddenAttribute: ('data', <zope.app.folder.folder.Folder object at
0x4129aaac>)
So, self.context is a folder object. The file that I'm publishing is
coming from the filesystem - could that be the problem ?
Cheers, Andrew.
FB wrote:
> 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
--
-----------------------------------
Reurbanise - Urban Sustainability
ph: (03) 3528 055, mobile: 0274 992 569
http://www.reurbanise.co.nz
More information about the Zope3-users
mailing list