Commit 500bde5a authored by Julien Muchembled's avatar Julien Muchembled

Reinitialize all subclasses when class hierarchy changes, and add unit test

This fixes testERP5Commerce.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@39714 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent c663257f
# -*- coding: utf-8 -*-
import sys
import gc, sys
from Products.ERP5Type.Base import Base as ERP5Base
from ExtensionClass import Base as ExtensionBase
from ZODB.broken import Broken, PersistentBroken
......@@ -12,6 +12,14 @@ ERP5BaseBroken = type('ERP5BaseBroken', (Broken, ERP5Base), dict(x
for x in PersistentBroken.__dict__.iteritems()
if x[0] not in ('__dict__', '__module__', '__weakref__')))
ExtensionClass = type(ExtensionBase)
def InitializePortalTypeClass(klass):
# beware of the scary meta type
ExtensionClass.__init__(klass, klass)
for klass in gc.get_referrers(klass):
if isinstance(klass, ExtensionClass):
InitializePortalTypeClass(klass)
def generateLazyPortalTypeClass(portal_type_name,
portal_type_class_loader):
def load(self, attr):
......@@ -41,8 +49,7 @@ def generateLazyPortalTypeClass(portal_type_name,
for key, value in attributes.iteritems():
setattr(klass, key, value)
# beware of the scary meta type
type(ExtensionBase).__init__(klass, klass)
InitializePortalTypeClass(klass)
return getattr(self, attr)
......
......@@ -33,14 +33,13 @@ import inspect
from types import ModuleType
from dynamic_module import registerDynamicModule
from lazy_class import generateLazyPortalTypeClass
from lazy_class import generateLazyPortalTypeClass, InitializePortalTypeClass
from Products.ERP5Type.Base import _aq_reset
from Products.ERP5Type.Globals import InitializeClass
from Products.ERP5Type.Utils import setDefaultClassProperties
from Products.ERP5Type import document_class_registry, mixin_class_registry
from Products.ERP5Type import PropertySheet as FilesystemPropertySheet
from ExtensionClass import Base as ExtensionBase
from zLOG import LOG, ERROR, INFO
def _importClass(classpath):
......@@ -241,7 +240,7 @@ def initializeDynamicModules():
class TempDocument(klass):
isTempDocument = PropertyConstantGetter('isTempDocument', value=True)
__roles__ = None
TempDocument.__name__ = "Temp" + portal_type_name
TempDocument.__name__ = "Temp " + portal_type_name
# Replace some attributes.
for name in ('isIndexable', 'reindexObject', 'recursiveReindexObject',
......@@ -309,7 +308,7 @@ def synchronizeDynamicModules(context, force=False):
if attr != '__module__':
delattr(klass, attr)
klass.__bases__ = ghostbase
type(ExtensionBase).__init__(klass, klass)
InitializePortalTypeClass(klass)
# Clear accessor holders of ZODB Property Sheets
_clearAccessorHolderModule(erp5.zodb_accessor_holder)
......
......@@ -31,7 +31,7 @@
import unittest
import transaction
from Products.ERP5Type.dynamic.portal_type_class import synchronizeDynamicModules
from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase
from Products.ERP5Type.tests.backportUnittest import skip
......@@ -141,6 +141,21 @@ class TestPortalTypeClass(ERP5TypeTestCase):
person_type.setTypeClass('Person')
transaction.commit()
def testTempPortalType(self):
newType = self.portal.portal_types.newContent
new_type_list = [newType(portal_type='Base Type', type_class='Folder',
type_filter_content_type=False).getId()
for i in (0, 1)]
newDocument = self.portal.newContent(self.id(), 'Folder').newContent
for temp_first, portal_type in enumerate(new_type_list):
obj = newDocument(portal_type='Folder', temp_object=temp_first)
obj.newContent('file', portal_type)
obj.file.aq_base
obj = newDocument(portal_type='Folder', temp_object=not temp_first)
obj.newContent('file', portal_type)
obj.file.aq_base
class TestZodbPropertySheet(ERP5TypeTestCase):
"""
XXX: WORK IN PROGRESS
......
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