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 -*- # -*- coding: utf-8 -*-
import sys import gc, sys
from Products.ERP5Type.Base import Base as ERP5Base from Products.ERP5Type.Base import Base as ERP5Base
from ExtensionClass import Base as ExtensionBase from ExtensionClass import Base as ExtensionBase
from ZODB.broken import Broken, PersistentBroken from ZODB.broken import Broken, PersistentBroken
...@@ -12,6 +12,14 @@ ERP5BaseBroken = type('ERP5BaseBroken', (Broken, ERP5Base), dict(x ...@@ -12,6 +12,14 @@ ERP5BaseBroken = type('ERP5BaseBroken', (Broken, ERP5Base), dict(x
for x in PersistentBroken.__dict__.iteritems() for x in PersistentBroken.__dict__.iteritems()
if x[0] not in ('__dict__', '__module__', '__weakref__'))) 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, def generateLazyPortalTypeClass(portal_type_name,
portal_type_class_loader): portal_type_class_loader):
def load(self, attr): def load(self, attr):
...@@ -41,8 +49,7 @@ def generateLazyPortalTypeClass(portal_type_name, ...@@ -41,8 +49,7 @@ def generateLazyPortalTypeClass(portal_type_name,
for key, value in attributes.iteritems(): for key, value in attributes.iteritems():
setattr(klass, key, value) setattr(klass, key, value)
# beware of the scary meta type InitializePortalTypeClass(klass)
type(ExtensionBase).__init__(klass, klass)
return getattr(self, attr) return getattr(self, attr)
......
...@@ -33,14 +33,13 @@ import inspect ...@@ -33,14 +33,13 @@ import inspect
from types import ModuleType from types import ModuleType
from dynamic_module import registerDynamicModule 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.Base import _aq_reset
from Products.ERP5Type.Globals import InitializeClass from Products.ERP5Type.Globals import InitializeClass
from Products.ERP5Type.Utils import setDefaultClassProperties from Products.ERP5Type.Utils import setDefaultClassProperties
from Products.ERP5Type import document_class_registry, mixin_class_registry from Products.ERP5Type import document_class_registry, mixin_class_registry
from Products.ERP5Type import PropertySheet as FilesystemPropertySheet from Products.ERP5Type import PropertySheet as FilesystemPropertySheet
from ExtensionClass import Base as ExtensionBase
from zLOG import LOG, ERROR, INFO from zLOG import LOG, ERROR, INFO
def _importClass(classpath): def _importClass(classpath):
...@@ -241,7 +240,7 @@ def initializeDynamicModules(): ...@@ -241,7 +240,7 @@ def initializeDynamicModules():
class TempDocument(klass): class TempDocument(klass):
isTempDocument = PropertyConstantGetter('isTempDocument', value=True) isTempDocument = PropertyConstantGetter('isTempDocument', value=True)
__roles__ = None __roles__ = None
TempDocument.__name__ = "Temp" + portal_type_name TempDocument.__name__ = "Temp " + portal_type_name
# Replace some attributes. # Replace some attributes.
for name in ('isIndexable', 'reindexObject', 'recursiveReindexObject', for name in ('isIndexable', 'reindexObject', 'recursiveReindexObject',
...@@ -309,7 +308,7 @@ def synchronizeDynamicModules(context, force=False): ...@@ -309,7 +308,7 @@ def synchronizeDynamicModules(context, force=False):
if attr != '__module__': if attr != '__module__':
delattr(klass, attr) delattr(klass, attr)
klass.__bases__ = ghostbase klass.__bases__ = ghostbase
type(ExtensionBase).__init__(klass, klass) InitializePortalTypeClass(klass)
# Clear accessor holders of ZODB Property Sheets # Clear accessor holders of ZODB Property Sheets
_clearAccessorHolderModule(erp5.zodb_accessor_holder) _clearAccessorHolderModule(erp5.zodb_accessor_holder)
......
...@@ -31,7 +31,7 @@ ...@@ -31,7 +31,7 @@
import unittest import unittest
import transaction import transaction
from Products.ERP5Type.dynamic.portal_type_class import synchronizeDynamicModules
from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase
from Products.ERP5Type.tests.backportUnittest import skip from Products.ERP5Type.tests.backportUnittest import skip
...@@ -141,6 +141,21 @@ class TestPortalTypeClass(ERP5TypeTestCase): ...@@ -141,6 +141,21 @@ class TestPortalTypeClass(ERP5TypeTestCase):
person_type.setTypeClass('Person') person_type.setTypeClass('Person')
transaction.commit() 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): class TestZodbPropertySheet(ERP5TypeTestCase):
""" """
XXX: WORK IN PROGRESS 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