Commit 316577a6 authored by Jérome Perrin's avatar Jérome Perrin

- implement get${base_category}TranslatedLogicalPath accessors.

- add missing tests for get${base_category}LogicalPath acessors.
- note an interesting behaviour in setDefault${base_category}Value



git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@39501 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent ae947408
......@@ -569,6 +569,7 @@ class DefaultLogicalPathGetter(BaseGetter):
func_code.co_varnames = ('self',)
func_code.co_argcount = 1
func_defaults = ()
_item_method = 'getTitle'
def __init__(self, id, key):
self._id = id
......@@ -581,14 +582,18 @@ class DefaultLogicalPathGetter(BaseGetter):
portal_type=kw.get('portal_type',()),
checked_permission=kw.get('checked_permission', None))
if value is not None:
return value.getLogicalPath()
else:
return None
return value.getLogicalPath(item_method=self._item_method)
return None
psyco.bind(__call__)
LogicalPathGetter = DefaultLogicalPathGetter
class DefaultTranslatedLogicalPathGetter(DefaultLogicalPathGetter):
_item_method = "getTranslatedTitle"
TranslatedLogicalPathGetter = DefaultTranslatedLogicalPathGetter
class IdListGetter(BaseGetter):
"""
Gets a list of reference objects uid
......@@ -640,6 +645,7 @@ class LogicalPathListGetter(BaseGetter):
func_code.co_varnames = ('self',)
func_code.co_argcount = 1
func_defaults = ()
_item_method = 'getTitle'
def __init__(self, id, key):
self._id = id
......@@ -647,7 +653,8 @@ class LogicalPathListGetter(BaseGetter):
self._key = key
def __call__(self, instance, *args, **kw):
return [x.getLogicalPath() for x in instance._getAcquiredValueList(self._key,
return [x.getLogicalPath(item_method=self._item_method)
for x in instance._getAcquiredValueList(self._key,
spec=kw.get('spec',()),
filter=kw.get('filter', None),
portal_type=kw.get('portal_type',()),
......
......@@ -2439,12 +2439,19 @@ def createValueAccessors(property_holder, id,
if not hasattr(property_holder, accessor_name):
property_holder.registerAccessor(accessor_name, id, Value.DefaultLogicalPathGetter, ())
property_holder.declareProtected(read_permission, accessor_name)
accessor_name = 'get' + UpperCase(id) + 'TranslatedLogicalPath'
if not hasattr(property_holder, accessor_name):
property_holder.registerAccessor(accessor_name, id, Value.DefaultTranslatedLogicalPathGetter, ())
property_holder.declareProtected(read_permission, accessor_name)
accessor_name = '_categoryGetDefault' + UpperCase(id) + 'LogicalPath'
if not hasattr(property_holder, accessor_name):
property_holder.registerAccessor(accessor_name, id, Value.DefaultLogicalPathGetter, ())
accessor_name = '_categoryGet' + UpperCase(id) + 'LogicalPath'
if not hasattr(property_holder, accessor_name):
property_holder.registerAccessor(accessor_name, id, Value.DefaultLogicalPathGetter, ())
accessor_name = '_categoryGet' + UpperCase(id) + 'TranslatedLogicalPath'
if not hasattr(property_holder, accessor_name):
property_holder.registerAccessor(accessor_name, id, Value.DefaultTranslatedLogicalPathGetter, ())
setter_name = 'set' + UpperCase(id) + 'Value'
if not hasattr(property_holder, setter_name):
......
......@@ -1747,7 +1747,7 @@ class TestPropertySheet:
for View permission
"""
# Create a few categories
region_category = self.getPortal().portal_categories.region
region_category = self.portal.portal_categories.region
beta_id = "beta"
beta_title = "Beta System"
beta = region_category.newContent(
......@@ -1767,9 +1767,13 @@ class TestPropertySheet:
title = gamma_title, )
gamma_path = gamma.getCategoryRelativeUrl()
alpha = gamma.newContent(portal_type='Category',
id='alpha',
title='Alpha')
# Make sure categories are reindexed
transaction.commit()
self.tic()
self.tic()
self.assertEquals(beta.getRelativeUrl(), 'region/beta')
......@@ -1805,8 +1809,19 @@ class TestPropertySheet:
None,
foo.getRegionTitle(checked_permission=checked_permission))
# Check getCategoryValue accessor
# Check getCategoryLogicalPath accesor
foo.setDefaultRegionValue(beta)
self.assertEquals(beta_title, foo.getRegionLogicalPath())
foo.setDefaultRegionValue(alpha)
self.assertEquals('Gamma System/Alpha', foo.getRegionLogicalPath())
# Check getCategoryValue accessor
# XXX did you know ?
# calling setDefaultRegionValue here would append a default region, and
# the region list would be [beta, alpha].
# bug or feature ? I don't know ...
foo.setRegionValue(beta)
self.assertEquals(beta, foo.getRegionValue())
self.assertEquals(
None,
......@@ -2261,6 +2276,27 @@ class TestPropertySheet:
self.assertEquals('foo', doc.getTranslatedDummy())
self.assertEquals([], self.portal.Localizer.erp5_ui._translated)
def test_translated_category_accessors(self):
region_category = self.portal.portal_categories.region
gamma = region_category.newContent(portal_type="Category",
id="gamma",
title="Gamma System")
alpha = gamma.newContent(portal_type='Category',
id='alpha',
title='Alpha')
self.portal.Localizer = DummyLocalizer()
doc = self.portal.person_module.newContent(portal_type='Person',
region='gamma/alpha')
self.assertEquals('Alpha', doc.getRegionTranslatedTitle())
# the value of the category title is translated with erp5_content
self.assertEquals(['Alpha'], self.portal.Localizer.erp5_content._translated)
self.portal.Localizer.erp5_content._translated = []
self.assertEquals('Gamma System/Alpha', doc.getRegionTranslatedLogicalPath())
self.assertEquals(['Gamma System', 'Alpha'],
self.portal.Localizer.erp5_content._translated)
# _aq_reset should be called implicitly when the system configuration
# changes:
......
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