Hi, In true newbie style I have followed many examples of product making, but have got stuck going further.... I would like to subclass OrderedFolder, then as my product is created add a page template inside it. My code (patchwork of other examples) manages to create the OrderedFolderish item but no page template is created inside it. Please be indulgent I am not a programmer..... My code is below, TIA Marie from Products.OrderedFolder import OrderedFolder from mxm import mxmObjectManager from Products.PageTemplates.PageTemplate import PageTemplate class ESRFFolder(OrderedFolder.OrderedFolder, mxmObjectManager.mxmObjectManager): meta_type = 'ESRF Folder' _allowed_meta_types = ('ESRF Folder','Page Template','Image','File') _properties = ( {'id':'title', 'type':'string', 'mode':'w'}, {'id':'Summary', 'type':'text', 'mode':'w'}, ) def manage_addAction(self, id=None, REQUEST=None): "Add instance to parent ObjectManager" mxmObjectManager.addClass(self, id, ESRFFolder, REQUEST) constructors = (mxmObjectManager.manage_addForm, manage_addAction) def manage_afterAdd(self, item, container): Folder.manage_afterAdd(self, item, container) try: user=REQUEST['AUTHENTICATED_USER'] except: user=None if (user is not None) and not ( user.has_permission('Add Page Templates', self)): raise 'Unauthorized', ( 'You are not authorized to add Page Templates.' ) try: self._setObject('contents_html', PageTemplate.PageTemplate('contents_html')) except: pass
Take out the except: pass at the bottom of the code. If the PageTemplate is not being created due to an error, it will tell you the error. Generally doing an except: pass is considered bad practice as it can hide any problem and make code hard to debug. -- Andy McKay Agmweb Consulting http://www.agmweb.ca ----- Original Message ----- From: "Marie Robichon" <robichon@esrf.fr> To: <zope@zope.org> Sent: Tuesday, August 20, 2002 8:26 AM Subject: [Zope] Newbie product question
Hi,
In true newbie style I have followed many examples of product making, but have got stuck going further....
I would like to subclass OrderedFolder, then as my product is created add a page template inside it. My code (patchwork of other examples) manages to create the OrderedFolderish item but no page template is created inside it. Please be indulgent I am not a programmer.....
My code is below,
TIA
Marie
from Products.OrderedFolder import OrderedFolder from mxm import mxmObjectManager from Products.PageTemplates.PageTemplate import PageTemplate
class ESRFFolder(OrderedFolder.OrderedFolder, mxmObjectManager.mxmObjectManager):
meta_type = 'ESRF Folder'
_allowed_meta_types = ('ESRF Folder','Page Template','Image','File')
_properties = ( {'id':'title', 'type':'string', 'mode':'w'}, {'id':'Summary', 'type':'text', 'mode':'w'}, )
def manage_addAction(self, id=None, REQUEST=None): "Add instance to parent ObjectManager" mxmObjectManager.addClass(self, id, ESRFFolder, REQUEST)
constructors = (mxmObjectManager.manage_addForm, manage_addAction)
def manage_afterAdd(self, item, container): Folder.manage_afterAdd(self, item, container)
try: user=REQUEST['AUTHENTICATED_USER'] except: user=None
if (user is not None) and not ( user.has_permission('Add Page Templates', self)): raise 'Unauthorized', ( 'You are not authorized to add Page Templates.' ) try: self._setObject('contents_html', PageTemplate.PageTemplate('contents_html')) except: pass
_______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
Marie Robichon wrote:
try: self._setObject('contents_html', PageTemplate.PageTemplate('contents_html')) except: pass
This is really bad style as the try: except: will mask any errors that occur when you try and create the page template. Take the try: except: out and maybe you will find out what's really going on... cheers, Chris
Marie Robichon writes:
... My code (patchwork of other examples) manages to create the OrderedFolderish item but no page template is created inside it. try: self._setObject('contents_html', PageTemplate.PageTemplate('contents_html')) except: pass Remove the "try: ... except: pass" to see what goes wrong.
If you do not understand the exception, come back with the following information: Error Type, Error Value and the traceback (at least the last lines; the complete one, if it is not too long). Dieter
Marie Robichon wrote:
I would like to subclass OrderedFolder, then as my product is created add a page template inside it. My code (patchwork of other examples) manages to create the OrderedFolderish item but no page template is created inside it. Please be indulgent I am not a programmer.....
As it is now your "manage_afterAdd" is an unbound function in the module. It really should be a class method for it to be called by Zope: from Products.OrderedFolder import OrderedFolder from mxm import mxmObjectManager from Products.PageTemplates.PageTemplate import PageTemplate class ESRFFolder(OrderedFolder.OrderedFolder, mxmObjectManager.mxmObjectManager): meta_type = 'ESRF Folder' _allowed_meta_types = ('ESRF Folder','Page Template','Image','File') _properties = ( {'id':'title', 'type':'string', 'mode':'w'}, {'id':'Summary', 'type':'text', 'mode':'w'}, ) def manage_afterAdd(self, item, container): Folder.manage_afterAdd(self, item, container) try: user=REQUEST['AUTHENTICATED_USER'] except: user=None if (user is not None) and not ( user.has_permission('Add Page Templates', self)): raise 'Unauthorized', ( 'You are not authorized to add Page Templates.' ) try: self._setObject('contents_html', PageTemplate.PageTemplate('contents_html')) except: pass def manage_addAction(self, id=None, REQUEST=None): "Add instance to parent ObjectManager" mxmObjectManager.addClass(self, id, ESRFFolder, REQUEST) constructors = (mxmObjectManager.manage_addForm, manage_addAction) regards Max M "klaatu verata niktu"
Hi, Thanks for your help, however when I move the manage_add method to the class level I get the following error when I try to instantiate my object: Error Type: RuntimeError Error Value: maximum recursion depth exceeded Traceback (innermost last): File C:\Program Files\ZopeAug2002\lib\python\ZPublisher\Publish.py, line 150, in publish_module File C:\Program Files\ZopeAug2002\lib\python\ZPublisher\Publish.py, line 114, in publish File C:\Program Files\ZopeAug2002\lib\python\Zope\__init__.py, line 159, in zpublisher_exception_hook File C:\Program Files\ZopeAug2002\lib\python\ZPublisher\Publish.py, line 98, in publish File C:\Program Files\ZopeAug2002\lib\python\ZPublisher\mapply.py, line 88, in mapply (Object: manage_addAction) File C:\Program Files\ZopeAug2002\lib\python\ZPublisher\Publish.py, line 39, in call_object (Object: manage_addAction) File C:\ZopeAug2002\Products\ESRFFolder\ESRFFolder.py, line 43, in manage_addAction File C:\ZopeAug2002\lib\python\mxm\mxmSimpleItem.py, line 124, in addClass File C:\Program Files\ZopeAug2002\lib\python\OFS\ObjectManager.py, line 267, in _setObject (Object: Zope) File C:\ZopeAug2002\Products\ESRFFolder\ESRFFolder.py, line 23, in manage_afterAdd (Object: test6) File C:\ZopeAug2002\Products\ESRFFolder\ESRFFolder.py, line 23, in manage_afterAdd (Object: test6) etc, etc, etc..... TIA Marie
Marie Robichon wrote:
Hi,
Thanks for your help, however when I move the manage_add method to the class level I get the following error when I try to instantiate my object:
Hmm ... this doesn't really help as I believe that you have changed the code since you posted it yesterday, so the Linenumbers are meaningless. But it seems that you are calling manage_afterAdd recursively. You are calling: "Folder.manage_afterAdd(self, item, container)" this should cause an error as there is no "Folder" object anywhere and I cannot see where you should get it from. If it really should read "container.manage_afterAdd(self, item, container)" then you are indeed calling your own object recursively as the container calls all it's subobjects with "manage_afterAdd" after being called with it. regards Max M "klaatu verata niktu"
participants (5)
-
Andy McKay -
Chris Withers -
Dieter Maurer -
Marie Robichon -
Max M