[Zope] Refresh after adding ZPT programmacilly

Nico de Boer nico@nfg.nl
12 Jun 2002 10:27:25 +0200


Hi all,

I've got some problems with my News product. For the rendering of it,
I let the site owner choose between DTML Methods and Zope Page
Templates. In the Add Form he can check a checkbox 'Add DTML Methods'
or a checkbox 'Add Page Templates' (or both).

In the __init__ method of my product this works as follows:

    def __init__(self, id, title='', zpt_add='', dtml_add=''):
        """Initialization News Product"""
        self.id = id
        self.title = title
        if dtml_add == 'yes': ## checkbox 'Add DTML Methods' checked
            self.dtmladd('init')
        if zpt_add == 'yes':  ## checkbox 'Add Page Template' checked
            self.zptadd('init')

The methods look like this:

    def zptadd(self, refresh=None):
        """Check whether to add a Zope Page Template"""
        self.createZPT(self, 'News_template',
                       '', self.init_News_template())
        if refresh is None:
                return self.manage_main(self, self.REQUEST)

    def dtmladd(self, refresh=None):
        """Check whether to add DTML methods"""
        if not hasattr(self, 'News_render'):
            self.createDTMLMethod('News_render', '', self.init_News_render())
        if not hasattr(self, 'Detail_inline'):
            self.createDTMLMethod('Detail_inline', '', self.init_Detail_inline())
        if not hasattr(self, 'News_detail'):
            self.createDTMLMethod('News_detail', '', self.init_News_detail())
        if not hasattr(self, 'News_chain'):
            self.createDTMLMethod('News_chain', '', self.init_News_chain())
        if not hasattr(self, 'News_childmenu'):
            self.createDTMLMethod('News_childmenu', '', self.init_News_childmenu())
        if not hasattr(self, 'News_peermenu'):
            self.createDTMLMethod('News_peermenu', '', self.init_News_peermenu())
        if not hasattr(self, 'local_css'):
            self.createDTMLMethod('local_css', '', self.init_style_sheet())
        if refresh is None:
            return self.manage_main(self, self.REQUEST)

Which calls createZPT:

    security.declareProtected('Change News','_createZPT')
    def createZPT(self, parent, id, title, content):
        """Add a PageTemplate to the News product"""
        parent._setObject(id, ZopePageTemplate.ZopePageTemplate(id, text=content))
	parent._getOb(id).pt_setTitle(title)

and refreshes manage_main. This works all fine. 

But afterwards, when the site owner has (by accident) deleted the
News_template, I want to give him the opportunity to add it again.

I have tried it like this:

    meta_types = (
        {'name': 'News DTML Methods',
	'action': 'manage_addProduct/News/dtmladd'},
        {'name': 'News Page Template', 'action': 'manage_addProduct/News/zptadd'},
        )

And this works. Only after you add the 'News Page Template' and the
manage_main is refreshed, the hyperlink on top of the manage_main 
is changed from (news is the current News object):

/Test/news

to:

/Test/news/manage_addProduct/News

and when I again add a 'News Page Template' it is changed to:

/Test/news/manage_addProduct/News/manage_addProduct/News

How can I keep the same hyperlink /Test/news as there is no News
Template added?

Greetz Nico