[Zope] Problems with namespace

Nico de Boer nico@nfg.nl
10 Jun 2002 14:41: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':
            self.dtmladd()
        if zpt_add == 'yes':
            self.zptadd()

One of the methods looks like this:

    def zptadd(self):
        """Check whether to add a Zope Page Template"""
        self.createZPT(self, 'News_template', '', self.init_News_template())

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)

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 Page Template', 'action': 'manage_addProduct/News/zptadd'},
        )

But this doesn't work, because I get the following error:

Traceback (innermost last):
  File /usr/lib/zope/lib/python/ZPublisher/Publish.py, line 150, in publish_module
  File /usr/lib/zope/lib/python/ZPublisher/Publish.py, line 114, in publish
  File /usr/lib/zope/lib/python/Zope/__init__.py, line 158, in zpublisher_exception_hook
  File /usr/lib/zope/lib/python/ZPublisher/Publish.py, line 98, in publish
  File /usr/lib/zope/lib/python/ZPublisher/mapply.py, line 88, in mapply
    (Object: zptadd)
  File /usr/lib/zope/lib/python/ZPublisher/Publish.py, line 39, in call_object
    (Object: zptadd)
  File /var/lib/zope/Products/News/News.py, line 218, in zptadd
    (Object: test)
  File /var/lib/zope/Products/News/News.py, line 225, in createZPT
    (Object: test)
  File /usr/lib/zope/lib/python/OFS/ObjectManager.py, line 219, in _setObject
    (Object: test)
  File /usr/lib/zope/lib/python/OFS/ObjectManager.py, line 72, in checkValidId
    (Object: test)
Bad Request: The id "News_template" is invalid--it is already in use.

Zope thinks that News_template already exists, but it doesn't.

Can somebody help me?

Greetz Nico