[Zope] differentiate dtml method from document
Tres Seaver
tseaver@palladion.com
Thu, 31 May 2001 08:23:21 -0400
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