Commit 73c1afc9 authored by Jérome Perrin's avatar Jérome Perrin

Add support for property sheets defining _categories with an expression


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@15780 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 7f8e6923
...@@ -2924,10 +2924,10 @@ class Base( CopyContainer, ...@@ -2924,10 +2924,10 @@ class Base( CopyContainer,
dynamic_accessor_list.append(subdochelper) dynamic_accessor_list.append(subdochelper)
if getattr(documented_item, property['id'], None) is not None: if getattr(documented_item, property['id'], None) is not None:
dynamic_property_list.append(subdochelper) dynamic_property_list.append(subdochelper)
if getattr(property_sheet, '_categories', None) is not None:
for category in property_sheet._categories: def visitCategory(category):
if category in seen_categories: if category in seen_categories:
continue return
seen_categories.append(category) seen_categories.append(category)
subdochelper = newTempDocumentationHelper(dochelper, category, title=category, subdochelper = newTempDocumentationHelper(dochelper, category, title=category,
content=pformat(documented_item.getCategoryMembershipList(category))) content=pformat(documented_item.getCategoryMembershipList(category)))
...@@ -2942,6 +2942,22 @@ class Base( CopyContainer, ...@@ -2942,6 +2942,22 @@ class Base( CopyContainer,
dynamic_accessor_list.append(subdochelper) dynamic_accessor_list.append(subdochelper)
dynamic_category_list.append(subdochelper) dynamic_category_list.append(subdochelper)
category_list = getattr(property_sheet, '_categories', [])
# some categories are defined by expressions, so we have to do 2
# passes, a first one to treat regular category list and collect
# categories defined by expression, a second one to treat thoses
# new categories from expressions.
expression_category_list = []
for category in category_list:
if isinstance(category, Expression):
econtext = createExpressionContext(self)
expression_category_list.extend(category(econtext))
continue
visitCategory(category)
for category in expression_category_list:
visitCategory(category)
# KEEPME: usefull to track the differences between accessors defined on # KEEPME: usefull to track the differences between accessors defined on
# PortalType and the one detected on the documented item. # PortalType and the one detected on the documented item.
# LOG('asDocumentationHelper', 0, found_accessors) # LOG('asDocumentationHelper', 0, found_accessors)
......
...@@ -128,6 +128,28 @@ class TestClassTool(ERP5TypeTestCase): ...@@ -128,6 +128,28 @@ class TestClassTool(ERP5TypeTestCase):
self.assertEquals(0, len(portal.portal_activities.getMessageList())) self.assertEquals(0, len(portal.portal_activities.getMessageList()))
def test_DocumentationHelperExpressionCategory(self):
# This tests checks that Documentation Helper works with propertysheets
# that define their categories using expressions.
from Products.ERP5Type.Document.Movement import Movement
from Products.CMFCore.Expression import Expression
movement = Movement('testing_id').__of__(self.getPortal())
# This test relies on the fact that Movement class has categories defined
# by an expression.
category_list = []
found_one = 0
for ps in movement.property_sheets:
for category in getattr(ps, '_categories', []):
if isinstance(category, Expression):
found_one = 1
if found_one:
break
else:
self.fail("Movement _categories doesn't include expressions; "
"this test is outdated")
self.assertNotEquals(None, movement.asDocumentationHelper())
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