Commit 4ad17f40 authored by Jérome Perrin's avatar Jérome Perrin

DocumentationHelper was broken because _aq_dynamic on temp objects now create

methods not on the class itself (a TempClass), but on the parent class. As a
consequence, it's no longer possible to create temp class without a "real"
class as parent class.



git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@14540 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 24dd5b37
...@@ -2968,6 +2968,7 @@ class TempBase(Base): ...@@ -2968,6 +2968,7 @@ class TempBase(Base):
security.declarePublic('edit') security.declarePublic('edit')
def newTempDocumentationHelper(folder, id, REQUEST=None, **kw): def newTempDocumentationHelper(folder, id, REQUEST=None, **kw):
o = TempDocumentationHelper(id) o = TempDocumentationHelper(id)
o = o.__of__(folder) o = o.__of__(folder)
...@@ -2975,7 +2976,8 @@ def newTempDocumentationHelper(folder, id, REQUEST=None, **kw): ...@@ -2975,7 +2976,8 @@ def newTempDocumentationHelper(folder, id, REQUEST=None, **kw):
o._edit(force_update=1, **kw) o._edit(force_update=1, **kw)
return o return o
class TempDocumentationHelper(TempBase):
class DocumentationHelper(Base):
""" """
Contains information about a documentable item. Contains information about a documentable item.
Documentable item can be any python type, instanciated or not. Documentable item can be any python type, instanciated or not.
...@@ -2996,6 +2998,8 @@ class TempDocumentationHelper(TempBase): ...@@ -2996,6 +2998,8 @@ class TempDocumentationHelper(TempBase):
return '%s%s' % (funcname[pos:], funcname[:pos]) return '%s%s' % (funcname[pos:], funcname[:pos])
def __cmp__(self, documentationhelper): def __cmp__(self, documentationhelper):
if not isinstance(documentationhelper, DocumentationHelper):
return -1
my_title = self._funcname_cmp_prepare(self.getTitle()) my_title = self._funcname_cmp_prepare(self.getTitle())
his_title = self._funcname_cmp_prepare(documentationhelper.getTitle()) his_title = self._funcname_cmp_prepare(documentationhelper.getTitle())
if my_title < his_title: if my_title < his_title:
...@@ -3003,3 +3007,14 @@ class TempDocumentationHelper(TempBase): ...@@ -3003,3 +3007,14 @@ class TempDocumentationHelper(TempBase):
if my_title > his_title: if my_title > his_title:
return 1 return 1
return 0 return 0
class TempDocumentationHelper(DocumentationHelper, TempBase):
"""Temporary version of Documentation Helper.
Actually we only use temporary instances of DocumentationHelper, but
as _aq_dynamic initialize methods on the base class for temp objects, it's
required that all temp objects have a corresponding "real" class as
klass.__bases__[0]
"""
...@@ -29,6 +29,8 @@ ...@@ -29,6 +29,8 @@
import os import os
import shutil import shutil
import tempfile import tempfile
import inspect
from pprint import pformat
from Products.CMFCore.utils import UniqueObject from Products.CMFCore.utils import UniqueObject
...@@ -44,6 +46,7 @@ from Products.ERP5Type import Permissions ...@@ -44,6 +46,7 @@ from Products.ERP5Type import Permissions
from Products.ERP5Type import _dtmldir from Products.ERP5Type import _dtmldir
from Products.ERP5Type.Tool.BaseTool import BaseTool from Products.ERP5Type.Tool.BaseTool import BaseTool
from Products.ERP5Type.Core.Folder import Folder from Products.ERP5Type.Core.Folder import Folder
from Products.ERP5Type import Document
from Products.ERP5Type.Utils import readLocalPropertySheet, writeLocalPropertySheet, getLocalPropertySheetList from Products.ERP5Type.Utils import readLocalPropertySheet, writeLocalPropertySheet, getLocalPropertySheetList
from Products.ERP5Type.Utils import readLocalExtension, writeLocalExtension, getLocalExtensionList from Products.ERP5Type.Utils import readLocalExtension, writeLocalExtension, getLocalExtensionList
...@@ -53,6 +56,7 @@ from Products.ERP5Type.Utils import readLocalConstraint, writeLocalConstraint, g ...@@ -53,6 +56,7 @@ from Products.ERP5Type.Utils import readLocalConstraint, writeLocalConstraint, g
from Products.ERP5Type.InitGenerator import getProductDocumentPathList from Products.ERP5Type.InitGenerator import getProductDocumentPathList
from Products.ERP5Type.Base import _aq_reset from Products.ERP5Type.Base import _aq_reset
from Products.ERP5Type.Base import newTempDocumentationHelper
from Products.ERP5Type import allowClassTool from Products.ERP5Type import allowClassTool
...@@ -833,9 +837,6 @@ def initialize( context ): ...@@ -833,9 +837,6 @@ def initialize( context ):
XXX: this code is (almost) duplicated from ERP5Types/Base.py:asDocumentationHelper XXX: this code is (almost) duplicated from ERP5Types/Base.py:asDocumentationHelper
""" """
from Products.ERP5Type import Document # XXX : Move to top
import inspect # XXX: Move to top
from pprint import pformat # XXX: move at top
my_class = getattr(getattr(Document, class_id), class_id) my_class = getattr(getattr(Document, class_id), class_id)
method_list = [] method_list = []
......
...@@ -94,6 +94,29 @@ class TestClassTool(ERP5TypeTestCase): ...@@ -94,6 +94,29 @@ class TestClassTool(ERP5TypeTestCase):
self.assertEqual(portal_classes.getLocalDocumentList(), ['Toto']) self.assertEqual(portal_classes.getLocalDocumentList(), ['Toto'])
# Test self-documentating features of ERP5Type documents through
# portal_classes.
def test_AsDocumentationHelperOnDocument(self):
# All Documents can be turned into a documentation helper
portal = self.getPortal()
folder = portal.newContent(portal_type='Folder', id='test_folder')
doc_helper = folder.asDocumentationHelper()
self.assertNotEquals(doc_helper, None)
# We simply check that we can access methods of the documentation helper
self.failUnless('Base' in doc_helper.getInheritanceList())
self.assertNotEquals([], doc_helper.getStaticMethodList())
def test_AsDocumentationHelperOnClassTool(self):
# From the class tool, we can get documentation helper for classes defining
# a Document
class_tool = self.getPortal().portal_classes
class_doc_helper = class_tool.asDocumentationHelper(class_id='Folder')
self.assertNotEquals(class_doc_helper, None)
# We simply check that we can access methods of the documentation helper
self.assertNotEquals([], class_doc_helper.getStaticPropertyList())
import unittest import unittest
def test_suite(): def test_suite():
suite = unittest.TestSuite() suite = unittest.TestSuite()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment