[Zope-dev] RE: [Zope] WebDAV or FTP "type"s?

Derek Simkowiak dereks@realloc.net
Wed, 26 Dec 2001 17:15:15 -0800 (PST)


-> Instead of creating a Product, you can just put an External Method in the
-> root of your site.

	A couple of weeks ago, I asked about customizing the default Zope
"type" when a file is uploaded with either WebDAV or FTP.  For example, 
I want ".html" files to be a ZopePageTemplate instead of a DTML Document, 
which is the default.

	Ron gave me the excellent suggestion of creating an "External
Method" that looks like the following:

-> def PUT_factory(self, name, typ, body):
->     """Make Page Template the default type for ftp uploads."""
->     from Products.PageTemplates.ZopePageTemplate import ZopePageTemplate
-> 
->     if typ == 'text/html':
->         return ZopePageTemplate(name)
->     return None


	Since then, I've done some learning, and now I'd like to
understand exactly *why* Ron's external method works.

	I'm creating a Zope Product that will introduce a new Zope "type"  
called "MIME Remapper".  This "MIME Remapper" will be a ZClass that has a
single property sheet, which allows you to associate particular MIME types
with particular Zope "types" using a nifty text field and dropdown.

	The problem is, I don't understand why Ron's suggestion actually
works.  I assume that the method PUT_factory() is over-riding the built-in
default, and when it returns None (for an unknown MIME type), Zope --for
some magical reason-- falls back to its built-in PUT_factory() to figure 
out the MIME type.  Is that right?

	Now, does that mean that the only way to override PUT_factory() is
via an external method?  If so, why is that?  If not, can I create a new
ZClass that has a method called PUT_factory()?  Will a new instance of my
ZClass mean that PUT_factory() is overridden for the folder the instance
is in?  If so, then why is Zope finding the PUT_factory() of my new "MIME
Remapper" type when it actually wants the PUT_factory() for the folder
that I'm in?  Do I need to redefine the PUT_factory() of the instance's
folder?  How do I do that?

	Obviously, I'm confused.  I feel like this particular problem will
give me good insight into how Zope works, so I'd love an explanation of
why Ron's PUT_factory() works.  (FYI, I understand class inheritance, 
just not within the Zope framework.)


Thanks,
Derek Simkowiak
dereks@realloc.net