[ZPT] Default POST type

Martijn Pieters mj@digicool.com
Wed, 18 Apr 2001 16:15:31 +0200


On Wed, Apr 18, 2001 at 11:03:50AM -0400, Sim Harbert wrote:
> Sorry, but I guess I am not enough of a Zope/Python guru to figure this out
> myself.  What exactly do I need in the 'PUT_factory' function to get it to
> create a Page Template instead of a DTML object?  I may get this if I keep
> plugging away, but it isn't obvious to me yet.

You need to create an External Method that'll create a ZPageTemplate
object to be used to create the new object.

An example:

  from Products.PageTemplates.ZopePageTemplate import ZopePageTemplate

  def PUT_factory(self, name, typ, body):
      if typ in ('text/html', 'text/xml'):
           return ZPageTemplate(name, content_type=typ)
      return None

If you save that as an External Method, and add it to a Folder where you
want to be able to create ZPT objects when you upload HTML pages. 

This example PUT_hook will create a ZPT for you when the content type is
text/html or text/xml. You can alter the if clause to create it under
different circumstances, of course. You could sniff out the uploaded body
(the 'body' parameter), or the id of the object (the 'name' parameter).

Hope this helps!

-- 
Martijn Pieters
| Software Engineer  mailto:mj@digicool.com
| Digital Creations  http://www.digicool.com/
| Creators of Zope   http://www.zope.org/
---------------------------------------------