[Zope] Folder specific templates for DTML Document
Maik Jablonski
maik.jablonski@uni-bielefeld.de
Fri, 12 Apr 2002 20:43:20 +0200
hello,
I need different DTML-Document-"Templates" (different source and
properties) for different folders, but I don't want to create a (Z)Class
for everything.
So when a user adds a DTML Document in the folder 'Students'
he should get the 'Students'-Default-DTML-Document (with properties like name,
address, email), when adding a DTML Document in folder Events he should get
the Event-Default-DTML-Document (properties like date, headline, description).
My idea is a "patch" for DTMLDocument/addDTMLDocument: When a
DTML Document with the name "standard_dtml_document" can be aquired, this will
be cloned/copied into the new created DTML Document... with source and
properties.
So I can put my students-default-DTML-Document as "standard_dtml_document"
into the students-folder, dito for my events-default-DTML-Document.
Question: How can I "overwrite" (in a Product) the original addDTMLDocument
with my own method (code see below), so I don't have to change
OFS/DTMLDocument.py(thinking of ZOPE-updates)?
Or is there already an existing solution which I did not see?
Thank you, maik.
***
def addDTMLDocument(self, id, title='', file='', REQUEST=None, submit=None):
"""Add a DTML Document object with the contents of file. If
'file' is empty, default document text is used.
"""
if type(file) is not type(''): file=file.read()
id = str(id)
title = str(title)
if not file:
if (hasattr(self,'standard_dtml_document') and
self.standard_dtml_document.meta_type=='DTML Document'):
self.manage_clone(self.standard_dtml_document,id,REQUEST)
else:
ob=DTMLDocument(standard_dtml_document, __name__=id)
ob.title=title
id=self._setObject(id, ob)
else:
ob=DTMLDocument(file, __name__=id)
ob.title=title
id=self._setObject(id, ob)
if REQUEST is not None:
try: u=self.DestinationURL()
except: u=REQUEST['URL1']
if submit==" Add and Edit ": u="%s/%s" % (u,quote(id))
REQUEST.RESPONSE.redirect(u+'/manage_main')
return ''