Commit 0b80c75d authored by Jean-Paul Smets's avatar Jean-Paul Smets

Prevent ZODB from exploding. Make class accessor stronger. Make system more dynamic.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@11884 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent ec1e6656
...@@ -26,6 +26,8 @@ import Products ...@@ -26,6 +26,8 @@ import Products
from zLOG import LOG from zLOG import LOG
_MARKER = {}
class TranslationProviderBase: class TranslationProviderBase:
""" """
Provide Translation Tabs and management methods for PropertyTranslationDomain Provide Translation Tabs and management methods for PropertyTranslationDomain
...@@ -43,8 +45,8 @@ class TranslationProviderBase: ...@@ -43,8 +45,8 @@ class TranslationProviderBase:
, ,
) )
security.declarePrivate( 'createInitialPropertyTranslationDomainDict' ) security.declarePrivate( 'updateInitialPropertyTranslationDomainDict' )
def createInitialPropertyTranslationDomainDict(self, ): def updateInitialPropertyTranslationDomainDict(self, ):
""" """
Create the initial list of association between property and domain name Create the initial list of association between property and domain name
""" """
...@@ -53,7 +55,7 @@ class TranslationProviderBase: ...@@ -53,7 +55,7 @@ class TranslationProviderBase:
# get the klass of the object based on the constructor document # get the klass of the object based on the constructor document
m = Products.ERP5Type._m m = Products.ERP5Type._m
ptype_name = ''.join(ptype_object.id.split(' ')) ptype_name = ''.join(ptype_object.id.split(' '))
constructor = 'add%s' %(ptype_name) constructor = self.factory # This is safer than: 'add%s' %(ptype_name)
klass = None klass = None
for method, doc in m.items(): for method, doc in m.items():
if method == constructor: if method == constructor:
...@@ -81,18 +83,30 @@ class TranslationProviderBase: ...@@ -81,18 +83,30 @@ class TranslationProviderBase:
if prop.get('translatable', 0): if prop.get('translatable', 0):
prop_id = prop['id'] prop_id = prop['id']
if not property_domain_dict.has_key(prop_id): if not property_domain_dict.has_key(prop_id):
property_domain_dict[prop_id] = TranslationInformation(prop_id, '') domain_name = prop.get('translation_domain', None)
property_domain_dict[prop_id] = TranslationInformation(prop_id, domain_name)
self._property_domain_dict = property_domain_dict
original_property_domain_dict = getattr(aq_base(self), '_property_domain_dict', {})
original_property_domain_keys = original_property_domain_dict.keys()
property_domain_keys = property_domain_dict.keys()
property_domain_keys.sort()
original_property_domain_keys.sort()
# Only update if required in order to prevent ZODB to grow
if property_domain_keys != original_property_domain_keys:
# Update existing dict
property_domain_dict.update(original_property_domain_dict)
# And store
self._property_domain_dict = property_domain_dict
security.declarePrivate( 'getPropertyTranslationDomainDict' ) security.declarePrivate( 'getPropertyTranslationDomainDict' )
def getPropertyTranslationDomainDict(self,): def getPropertyTranslationDomainDict(self,):
""" """
Return all the translation defined by a provider. Return all the translation defined by a provider.
""" """
property_domain_dict = getattr(aq_base(self), '_property_domain_dict', {}) property_domain_dict = getattr(aq_base(self), '_property_domain_dict', _MARKER)
if len(property_domain_dict) == 0: if len(property_domain_dict) is _MARKER:
self.createInitialPropertyTranslationDomainDict() # Force update is not defined
self.updateInitialPropertyTranslationDomainDict()
return self._property_domain_dict return self._property_domain_dict
# #
...@@ -103,6 +117,7 @@ class TranslationProviderBase: ...@@ -103,6 +117,7 @@ class TranslationProviderBase:
""" Show the 'Translation' management tab. """ Show the 'Translation' management tab.
""" """
translation_list = [] translation_list = []
self.updateInitialPropertyTranslationDomainDict() # Force update in case of change of PS list
prop_domain_name_dict = self.getPropertyTranslationDomainDict() prop_domain_name_dict = self.getPropertyTranslationDomainDict()
keys = prop_domain_name_dict.keys() keys = prop_domain_name_dict.keys()
keys.sort() keys.sort()
...@@ -139,6 +154,9 @@ class TranslationProviderBase: ...@@ -139,6 +154,9 @@ class TranslationProviderBase:
if new_domain_name != prop_object.getDomainName(): if new_domain_name != prop_object.getDomainName():
prop_object.setDomainName(new_domain_name) prop_object.setDomainName(new_domain_name)
from Products.ERP5Type.Base import _aq_reset
_aq_reset() # Reset accessor cache
if REQUEST is not None: if REQUEST is not None:
return self.manage_editTranslationForm(REQUEST, manage_tabs_message= return self.manage_editTranslationForm(REQUEST, manage_tabs_message=
'Translations Updated.') 'Translations Updated.')
......
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