Re: [Zope] differentiate dtml method from document
dave@kovach.com wrote:
Is there a suffix I can add to DTML Methods that would then be
recognized by the ZODB upon creating an object externally like from
within Dreamweaver?
If I create an object externally and call it SOMEFILE.DTML
- it is recognized as a DTML Document. Ok, good. But, now I want to create a file that will be recognized
as a DTML METHOD.
Zope doesn't care primarily about the suffix; its PUT handling (for WebDAV/FTP/HTTP PUTs) looks at the Content-Type header (if there is one; no such luch with FTP), and only reverts to guessing type from extension if it is not there. You can override the default behavior using the 'PUT_factory' hook, described at: http://dev.zope.org/Wikis/DevSite/Proposals/HookablePUTCreation Essentially, you would drop in an ExternalMethod which did the name recognition you desired, e.g.:: # Implement the "hookable PUT" hook. import re, OFS.DTMLMethod NAME_PATTERN = re.compile( '^.*\.dtml$' ) def PUT_factory( self, name, typ, body ): """ """ if NAME_PATTERN.match( name ): return OFS.DTMLMethod.DTMLMethod( '', __name__=name ) return None Tres. -- =============================================================== Tres Seaver tseaver@digicool.com Digital Creations "Zope Dealers" http://www.zope.org
Please help. I've looked at http://dev.zope.org/Wikis/DevSite/Proposals/HookablePUTCreation and I think this will solve many migration problems, for moving existing Apache wrapped sever parsed pages into Zope. How do I use the hookable_PUT to add ZopePageTemplates or HTMLDocuments? -Dondi
Dondi Bogusky wrote:
Please help. I've looked at http://dev.zope.org/Wikis/DevSite/Proposals/HookablePUTCreation and I think this will solve many migration problems, for moving existing Apache wrapped sever parsed pages into Zope. How do I use the hookable_PUT to add ZopePageTemplates or HTMLDocuments?
You create a method called 'PUT_factory' (an ExternalMethod is easiest, or a method of a Python class; PythonScripts will typically need help to get at the "raw" classes they need for this). This method looks at the three parameters which Zope's PUT machinery pases to it (see webdav.NullResource), in order to determine what kind of object should be instantiated in response to a WebDAV/FTP/HTTP PUT directed to a non-existant URL. For example, here is the version from the CMF SkinsTool, formatted to fit your screen :):: from Products.Pythonscripts import PythonScript from OFS.Image import Image from OFS.DTMLMethod import DTMLMethod try: from Products.PageTemplates.ZopePageTemplate import ZopePageTemplate SUPPORTS_PAGE_TEMPLATES=1 except ImportError: SUPPORTS_PAGE_TEMPLATES=0 def PUT_factory( self, name, typ, body ): """ Create an appropriate "skin method". """ major, minor = split( typ, '/' ) if major == 'image': return Image( id=name , title='' , file='' , content_type=typ ) if major == 'text': if minor == 'x-python': return PythonScript( id=name ) if minor in ( 'html', 'xml' ) and SUPPORTS_PAGE_TEMPLATES: return ZopePageTemplate( name ) return DTMLMethod( __name__=name ) return None # Let NullResource figure it out, then Note a couple of conventions here: - The put factory is just supposed to make an "empty" instance of the appropriate class; the NullResource is going to delegate the actual PUT invocation to the new instance immediately, so you don't need to handle that. The only reason the body is passed is to allow the PUT_factory to "sniff" it, if name and typ aren't sufficient. - The PUT_factory is not responsible for "seating" the new instance into its container. - Returning None from the PUT_factory allows NullResource to do the standard default, which is: o all 'image/*' -> OFS.Image.Image o all 'text/*' -> OFS.DTMLDocument.DTMLDocument (*not* Method!) o all else -> OFS.Image.File Hope that helps, Tres. --=============================================================== Tres Seaver tseaver@digicool.com Digital Creations "Zope Dealers" http://www.zope.org
participants (2)
-
Dondi Bogusky -
Tres Seaver