You are not logged in Log in Join
You are here: Home » Members » kslee » How-To Change your Default DTMLs

Log in
Name

Password

 

How-To Change your Default DTMLs

Warning, this How-To is written by non-native English writer, hence may contain errors might lead your Zope to fatal results.

Why You may change the Default DTML Method and Document

While developing sites, I found myself frequently modifying the default DTMLs like this:
default DTML                              after modification
<dtml-var standard_html_header>   -->    <dtml-var "my_site_html_header(_, _, x=y)">
Yes, this might be becuase I did bad site design. But I guess the flexiblity to configure the default DTML contens is Good ThingTM. Furthurmore, when I change standard_html_header/footer into some more complex error-abunduant forms, even tracebacks look far more ugly.

So How You Can Change the Default DTMLs?

In short, you should edit the Zope source. If you do not have the access to the your Zope source code, you can not but ask the superuser and wait.

In the Your_Zope_Directory/lib/python/OFS directory, there is DTMLMethod.py and DTMLDocument.py. You will edit both of them.

Open DTMLMethod.py with your favorite editor.
Find "def addDTMLMethod". It's at the end of the file. For my Zope installation(it's version 2.0.1 Linux binary install), it's at Line 383
Now the source of addDTMLMethod:

def addDTMLMethod(self, id, title='', file='', REQUEST=None, submit=None):
    """Add a DTML Method object with the contents of file. If
    'file' is empty, default document text is used.
    """
    if type(file) is not type(''): file=file.read()
    if not file: file=default_dm_html                    <--You'll change this line.
    ob=DTMLMethod(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 ''

Change the above indicated line as the following:
    if not file:
        if hasattr(self, 'default_dm_html') and self.default_dm_html: file=self.default_dm_html.read()
        else: file=default_dm_html
So you inserted two more lines.
Now edit the DTMLDocument.py in the same way. It's addDTMLDocument method, which is corresponding addDTMLMehod method of DTMLDocument.py, is at line 193 (in my case).
Just do the same except that now "default_dm_html" is "default_dd_html".
And now restart your Zope.

How You Can abuse the New Flexiblity

Suppose you have the follwing folder structure:
/foo/babo1/babo2
     imsi1/imsi2
 bar/blabl/blabl
If you want to change the both of the defualt DTMLs in the foo branch create default_dm_html and default_dd_html in the foo folder. default_dm_html and default_dd_html can be DTML Document or DTML Method. That does not matter.

If you need different default_dm_html in the babo1 folder, just create anoter default_dm_html.

What if you want the newly created DTML Document under imsi1 branch has the origianl default contents?
Just create a 'default_dd_html' property in the imsi1 folder. It might be string or boolean or integer. Actually anything is OK if it is 'False': i.e., zero-lenth string, boolean set to false, integer set to 0 ... ...
Then you can have original defaut DTML Documents under imsi1 folder.

What if you create non-false default_dm(or dd)_html property?
You will see a traceback saying that type of property does not have read() method.
Actually, there are several ways to make you never see that sort of tracebacks, but they require more codes. So I do not want make more complex this probably-most-frequently-used addDTMLMethod(or Document) method.

Lastly ...

I hope this kludge be help to other Zopistas and someday those wonderfull DC people put this or simillar code into the official Zope source base.
I suppose those Zope Hosting Providers can utilize this in various way, though they may already have their own ways.
Last but least, do not forget to put an appropriate attribution in your default_xx_htmls.

p.s. I have retired from the Zope list. Simply 100+ mails per day is over my capacity to handle. Hence please send any comments and questions to my email address. Complaints will be redirected to /dev/null. You are sufficiently warned.