Commit 9fe6eba8 authored by Jérome Perrin's avatar Jérome Perrin

Minor style changes


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@7513 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 5c88e154
...@@ -45,15 +45,16 @@ from Products.ERP5Type import Constraint ...@@ -45,15 +45,16 @@ from Products.ERP5Type import Constraint
from Products.ERP5Type import Interface from Products.ERP5Type import Interface
from Products.ERP5Type import PropertySheet from Products.ERP5Type import PropertySheet
from zLOG import LOG, PROBLEM from zLOG import LOG, BLATHER, PROBLEM
##################################################### #####################################################
# Global Switches # Global Switches
##################################################### #####################################################
INITIALIZE_PRODUCT_RAD = 1 # If set to 0, product documents are not initialized INITIALIZE_PRODUCT_RAD = 1 # If set to 0, product documents are not
# this will divide by two memory usage taken by getters and setters # initialized this will divide by two memory
# 0 value is suggested for new ERP5 projetcs # usage taken by getters and setters 0 value
# is suggested for new ERP5 projetcs
##################################################### #####################################################
# Compatibility - XXX - BAD # Compatibility - XXX - BAD
...@@ -81,7 +82,7 @@ def sortValueList(value_list, sort_on=None, sort_order=None, **kw): ...@@ -81,7 +82,7 @@ def sortValueList(value_list, sort_on=None, sort_order=None, **kw):
if len(key) == 1: if len(key) == 1:
new_sort_on.append((key[0], reverse, None)) new_sort_on.append((key[0], reverse, None))
elif len(key) == 2: elif len(key) == 2:
new_sort_on.append((key[0], new_sort_on.append((key[0],
key[1] in ('descending', 'reverse', 'DESC'), key[1] in ('descending', 'reverse', 'DESC'),
None)) None))
else: else:
...@@ -94,7 +95,7 @@ def sortValueList(value_list, sort_on=None, sort_order=None, **kw): ...@@ -94,7 +95,7 @@ def sortValueList(value_list, sort_on=None, sort_order=None, **kw):
else: else:
# XXX: For an unknown type, use a string. # XXX: For an unknown type, use a string.
f=str f=str
new_sort_on.append((key[0], new_sort_on.append((key[0],
key[1] in ('descending', 'reverse', 'DESC'), key[1] in ('descending', 'reverse', 'DESC'),
f)) f))
sort_on = new_sort_on sort_on = new_sort_on
...@@ -117,7 +118,7 @@ def sortValueList(value_list, sort_on=None, sort_order=None, **kw): ...@@ -117,7 +118,7 @@ def sortValueList(value_list, sort_on=None, sort_order=None, **kw):
break break
return result return result
if isinstance(value_list,LazyMap): if isinstance(value_list, LazyMap):
new_value_list = [x for x in value_list] new_value_list = [x for x in value_list]
value_list = new_value_list value_list = new_value_list
value_list.sort(sortValues) value_list.sort(sortValues)
...@@ -174,6 +175,8 @@ def cartesianProduct(list_of_list): ...@@ -174,6 +175,8 @@ def cartesianProduct(list_of_list):
# Some list operations # Some list operations
def keepIn(value_list, filter_list): def keepIn(value_list, filter_list):
# XXX this is [x for x in value_list if x in filter_list]
warn()
result = [] result = []
for k in value_list: for k in value_list:
if k in filter_list: if k in filter_list:
...@@ -181,6 +184,7 @@ def keepIn(value_list, filter_list): ...@@ -181,6 +184,7 @@ def keepIn(value_list, filter_list):
return result return result
def rejectIn(value_list, filter_list): def rejectIn(value_list, filter_list):
# XXX this is [x for x in value_list if x not in filter_list]
result = [] result = []
for k in value_list: for k in value_list:
if not(k in filter_list): if not(k in filter_list):
...@@ -210,19 +214,18 @@ def pathToUid(list): ...@@ -210,19 +214,18 @@ def pathToUid(list):
# Path # Path
def getPath(object_or_path, **kw): def getPath(object_or_path, **kw):
""" """Returns the absolute path of an object
Returns the absolute path of an object """
""" if isinstance(object_or_path, (list, tuple)):
if isinstance(object_or_path, (list, tuple)): path = '/'.join(object_or_path)
path = '/'.join(object_or_path) elif isinstance(object_or_path, str):
elif isinstance(object_or_path, str): path = object_or_path
path = object_or_path else:
else: path = object_or_path.getPhysicalPath()
path = object_or_path.getPhysicalPath() path = '/'.join(path)
path = '/'.join(path) if kw.get('tuple'):
if kw.get('tuple'): return path.split('/')
return path.split('/') return path
return path
##################################################### #####################################################
...@@ -247,11 +250,13 @@ def getModuleIdList(product_path, module_id): ...@@ -247,11 +250,13 @@ def getModuleIdList(product_path, module_id):
module_name = file_name[0:-3] module_name = file_name[0:-3]
module_name_list += [module_name] module_name_list += [module_name]
except: except:
LOG('ERP5Type:',0,'No PropertySheet directory in %s' % product_path) LOG('ERP5Type:', BLATHER,
'No PropertySheet directory in %s' % product_path)
return path, module_name_list return path, module_name_list
# EPR5Type global modules update # EPR5Type global modules update
def updateGlobals( this_module, global_hook, permissions_module = None, is_erp5_type=0): def updateGlobals(this_module, global_hook,
permissions_module=None, is_erp5_type=0):
""" """
This function does all the initialization steps required This function does all the initialization steps required
for a Zope / CMF Product for a Zope / CMF Product
...@@ -265,16 +270,12 @@ def updateGlobals( this_module, global_hook, permissions_module = None, is_erp5_ ...@@ -265,16 +270,12 @@ def updateGlobals( this_module, global_hook, permissions_module = None, is_erp5_
# Update PropertySheet Registry # Update PropertySheet Registry
for module_id in ('PropertySheet', 'Interface', 'Constraint', ): for module_id in ('PropertySheet', 'Interface', 'Constraint', ):
path, module_id_list = getModuleIdList(product_path, module_id) path, module_id_list = getModuleIdList(product_path, module_id)
#print path
#print module_id_list
if module_id == 'PropertySheet': if module_id == 'PropertySheet':
import_method = importLocalPropertySheet import_method = importLocalPropertySheet
elif module_id == 'Interface': elif module_id == 'Interface':
import_method = importLocalInterface import_method = importLocalInterface
elif module_id == 'Constraint': elif module_id == 'Constraint':
import_method = importLocalConstraint import_method = importLocalConstraint
else:
import_method = None
for module_id in module_id_list: for module_id in module_id_list:
import_method(module_id, path=path) import_method(module_id, path=path)
...@@ -319,17 +320,17 @@ class DocumentConstructor(Method): ...@@ -319,17 +320,17 @@ class DocumentConstructor(Method):
def __init__(self, klass): def __init__(self, klass):
self.klass = klass self.klass = klass
def __call__(self, folder, id, REQUEST=None, activate_kw=None, is_indexable=None, **kw): def __call__(self, folder, id, REQUEST=None,
activate_kw=None, is_indexable=None, **kw):
o = self.klass(id) o = self.klass(id)
if activate_kw is not None: if activate_kw is not None:
o._v_activate_kw = activate_kw o._v_activate_kw = activate_kw
if is_indexable is not None: if is_indexable is not None:
o.isIndexable=is_indexable o.isIndexable = is_indexable
folder._setObject(id, o) folder._setObject(id, o)
# if no activity tool, the object has already an uid # if no activity tool, the object has already an uid
if getattr(aq_base(o),'uid',None) is None: if getattr(aq_base(o),' uid', None) is None:
o.uid = folder.portal_catalog.newUid() o.uid = folder.portal_catalog.newUid()
#LOG('DocumentConstructor', 0, 'o = %r, kw = %r' % (o, kw))
if kw: o.__of__(folder)._edit(force_update=1, **kw) if kw: o.__of__(folder)._edit(force_update=1, **kw)
if REQUEST is not None: if REQUEST is not None:
REQUEST['RESPONSE'].redirect( 'manage_main' ) REQUEST['RESPONSE'].redirect( 'manage_main' )
...@@ -339,16 +340,19 @@ class TempDocumentConstructor(DocumentConstructor): ...@@ -339,16 +340,19 @@ class TempDocumentConstructor(DocumentConstructor):
def __call__(self, folder, id, REQUEST=None, **kw): def __call__(self, folder, id, REQUEST=None, **kw):
o = self.klass(id) o = self.klass(id)
# Monkey patch TempBase specific arguments # Monkey patch TempBase specific arguments
for k in ('isIndexable', 'reindexObject', 'recursiveReindexObject', 'activate', 'setUid', 'setTitle', 'getTitle'): for k in ('isIndexable', 'reindexObject', 'recursiveReindexObject',
'activate', 'setUid', 'setTitle', 'getTitle'):
setattr(o, k, getattr(o,"_temp_%s" % k)) setattr(o, k, getattr(o,"_temp_%s" % k))
o = o.__of__(folder) o = o.__of__(folder)
if kw: o.__of__(folder)._edit(force_update=1, **kw) if kw:
o.__of__(folder)._edit(force_update=1, **kw)
return o return o
python_file_parser = re.compile('^(.*)\.py$') python_file_parser = re.compile('^(.*)\.py$')
def getLocalPropertySheetList(): def getLocalPropertySheetList():
if not getConfiguration: return [] if not getConfiguration:
return []
instance_home = getConfiguration().instancehome instance_home = getConfiguration().instancehome
path = os.path.join(instance_home, "PropertySheet") path = os.path.join(instance_home, "PropertySheet")
file_list = os.listdir(path) file_list = os.listdir(path)
...@@ -394,7 +398,6 @@ def importLocalPropertySheet(class_id, path = None): ...@@ -394,7 +398,6 @@ def importLocalPropertySheet(class_id, path = None):
f = open(path) f = open(path)
module = imp.load_source(class_id, path, f) module = imp.load_source(class_id, path, f)
setattr(PropertySheet, class_id, getattr(module, class_id)) setattr(PropertySheet, class_id, getattr(module, class_id))
#setattr(Products.ERP5Type.PropertySheet, class_id, getattr(module, class_id))
# Register base categories # Register base categories
registerBaseCategories(getattr(module, class_id)) registerBaseCategories(getattr(module, class_id))
...@@ -405,7 +408,6 @@ def registerBaseCategories(property_sheet): ...@@ -405,7 +408,6 @@ def registerBaseCategories(property_sheet):
if isinstance(category_list, str): if isinstance(category_list, str):
category_list = (category_list,) category_list = (category_list,)
for bc in category_list : for bc in category_list :
#LOG('registerBaseCategories', 0, 'bc = %r in %s' % (bc, property_sheet))
base_category_dict[bc] = 1 base_category_dict[bc] = 1
def importLocalInterface(class_id, path = None): def importLocalInterface(class_id, path = None):
...@@ -429,7 +431,8 @@ def importLocalConstraint(class_id, path = None): ...@@ -429,7 +431,8 @@ def importLocalConstraint(class_id, path = None):
setattr(Products.ERP5Type.Constraint, class_id, getattr(module, class_id)) setattr(Products.ERP5Type.Constraint, class_id, getattr(module, class_id))
def getLocalExtensionList(): def getLocalExtensionList():
if not getConfiguration: return [] if not getConfiguration:
return []
instance_home = getConfiguration().instancehome instance_home = getConfiguration().instancehome
path = os.path.join(instance_home, "Extensions") path = os.path.join(instance_home, "Extensions")
file_list = os.listdir(path) file_list = os.listdir(path)
...@@ -441,7 +444,8 @@ def getLocalExtensionList(): ...@@ -441,7 +444,8 @@ def getLocalExtensionList():
return result return result
def getLocalTestList(): def getLocalTestList():
if not getConfiguration: return [] if not getConfiguration:
return []
instance_home = getConfiguration().instancehome instance_home = getConfiguration().instancehome
path = os.path.join(instance_home, "tests") path = os.path.join(instance_home, "tests")
file_list = os.listdir(path) file_list = os.listdir(path)
...@@ -453,7 +457,8 @@ def getLocalTestList(): ...@@ -453,7 +457,8 @@ def getLocalTestList():
return result return result
def getLocalConstraintList(): def getLocalConstraintList():
if not getConfiguration: return [] if not getConfiguration:
return []
instance_home = getConfiguration().instancehome instance_home = getConfiguration().instancehome
path = os.path.join(instance_home, "Constraint") path = os.path.join(instance_home, "Constraint")
file_list = os.listdir(path) file_list = os.listdir(path)
...@@ -576,6 +581,8 @@ def writeLocalDocument(class_id, text, create=1): ...@@ -576,6 +581,8 @@ def writeLocalDocument(class_id, text, create=1):
f.write(text) f.write(text)
def setDefaultClassProperties(property_holder): def setDefaultClassProperties(property_holder):
"""Initialize default properties for ERP5Type Documents.
"""
if not property_holder.__dict__.has_key('isPortalContent'): if not property_holder.__dict__.has_key('isPortalContent'):
property_holder.isPortalContent = 1 property_holder.isPortalContent = 1
if not property_holder.__dict__.has_key('isRADContent'): if not property_holder.__dict__.has_key('isRADContent'):
...@@ -588,11 +595,13 @@ def setDefaultClassProperties(property_holder): ...@@ -588,11 +595,13 @@ def setDefaultClassProperties(property_holder):
property_holder.property_sheets = () property_holder.property_sheets = ()
# Add default factory type information # Add default factory type information
if not property_holder.__dict__.has_key('factory_type_information') and \ if not property_holder.__dict__.has_key('factory_type_information') and \
property_holder.__dict__.has_key('meta_type') and property_holder.__dict__.has_key('portal_type'): property_holder.__dict__.has_key('meta_type') and \
property_holder.__dict__.has_key('portal_type'):
property_holder.factory_type_information = \ property_holder.factory_type_information = \
{ 'id' : property_holder.portal_type { 'id' : property_holder.portal_type
, 'meta_type' : property_holder.meta_type , 'meta_type' : property_holder.meta_type
, 'description' : getattr(property_holder, '__doc__', "Type generated by ERPType") , 'description' : getattr(property_holder, '__doc__',
"Type generated by ERPType")
, 'icon' : 'document.gif' , 'icon' : 'document.gif'
, 'product' : 'ERP5Type' , 'product' : 'ERP5Type'
, 'factory' : 'add%s' % property_holder.__name__ , 'factory' : 'add%s' % property_holder.__name__
...@@ -626,11 +635,9 @@ def setDefaultClassProperties(property_holder): ...@@ -626,11 +635,9 @@ def setDefaultClassProperties(property_holder):
} }
def importLocalDocument(class_id, document_path = None): def importLocalDocument(class_id, document_path = None):
"""Imports a document class and registers it in ERP5Type Document
repository ( Products.ERP5Type.Document )
""" """
Imports a document class and registers it as
"""
#__import__('Document.Test')
import Products.ERP5Type.Document import Products.ERP5Type.Document
import Permissions import Permissions
import Products import Products
...@@ -640,21 +647,25 @@ def importLocalDocument(class_id, document_path = None): ...@@ -640,21 +647,25 @@ def importLocalDocument(class_id, document_path = None):
else: else:
path = document_path path = document_path
path = os.path.join(path, "%s.py" % class_id) path = os.path.join(path, "%s.py" % class_id)
# Import Document Class and Initialize it # Import Document Class and Initialize it
f = open(path) f = open(path)
document_module = imp.load_source('Products.ERP5Type.Document.%s' % class_id, path, f) # This is the right way document_module = imp.load_source(
'Products.ERP5Type.Document.%s' % class_id, path, f)
document_class = getattr(document_module, class_id) document_class = getattr(document_module, class_id)
document_constructor = DocumentConstructor(document_class) document_constructor = DocumentConstructor(document_class)
document_constructor_name = "add%s" % class_id document_constructor_name = "add%s" % class_id
document_constructor.__name__ = document_constructor_name document_constructor.__name__ = document_constructor_name
setattr(Products.ERP5Type.Document, class_id, document_module) setattr(Products.ERP5Type.Document, class_id, document_module)
setattr(Products.ERP5Type.Document, document_constructor_name, document_constructor) setattr(Products.ERP5Type.Document, document_constructor_name,
document_constructor)
setDefaultClassProperties(document_class) setDefaultClassProperties(document_class)
from AccessControl import ModuleSecurityInfo from AccessControl import ModuleSecurityInfo
ModuleSecurityInfo('Products.ERP5Type.Document').declareProtected(Permissions.AddPortalContent, ModuleSecurityInfo('Products.ERP5Type.Document').declareProtected(
document_constructor_name,) Permissions.AddPortalContent, document_constructor_name,)
InitializeClass(document_class) InitializeClass(document_class)
f.close() f.close()
# Temp documents are created as standard classes with a different constructor # Temp documents are created as standard classes with a different constructor
# which patches some methods are the instance level to prevent reindexing # which patches some methods are the instance level to prevent reindexing
from Products.ERP5Type import product_path as erp5_product_path from Products.ERP5Type import product_path as erp5_product_path
...@@ -662,8 +673,11 @@ def importLocalDocument(class_id, document_path = None): ...@@ -662,8 +673,11 @@ def importLocalDocument(class_id, document_path = None):
temp_document_constructor = TempDocumentConstructor(document_class) temp_document_constructor = TempDocumentConstructor(document_class)
temp_document_constructor_name = "newTemp%s" % class_id temp_document_constructor_name = "newTemp%s" % class_id
temp_document_constructor.__name__ = temp_document_constructor_name temp_document_constructor.__name__ = temp_document_constructor_name
setattr(Products.ERP5Type.Document, temp_document_constructor_name, temp_document_constructor) setattr(Products.ERP5Type.Document,
ModuleSecurityInfo('Products.ERP5Type.Document').declarePublic(temp_document_constructor_name,) temp_document_constructor_name,
temp_document_constructor)
ModuleSecurityInfo('Products.ERP5Type.Document').declarePublic(
temp_document_constructor_name,)
# Update Meta Types # Update Meta Types
new_meta_types = [] new_meta_types = []
...@@ -675,7 +689,8 @@ def importLocalDocument(class_id, document_path = None): ...@@ -675,7 +689,8 @@ def importLocalDocument(class_id, document_path = None):
instance_class = None instance_class = None
new_meta_types.append( new_meta_types.append(
{ 'name': document_class.meta_type, { 'name': document_class.meta_type,
'action': ('manage_addProduct/%s/%s' % ('ERP5Type', document_constructor_name)), 'action': ('manage_addProduct/%s/%s' % (
'ERP5Type', document_constructor_name)),
'product': 'ERP5Type', 'product': 'ERP5Type',
'permission': document_class.add_permission, 'permission': document_class.add_permission,
'visibility': 'Global', 'visibility': 'Global',
...@@ -690,7 +705,8 @@ def importLocalDocument(class_id, document_path = None): ...@@ -690,7 +705,8 @@ def importLocalDocument(class_id, document_path = None):
constructors = ( manage_addContentForm constructors = ( manage_addContentForm
, manage_addContent , manage_addContent
, document_constructor , document_constructor
, ('factory_type_information', document_class.factory_type_information) ) , ('factory_type_information',
document_class.factory_type_information) )
else: else:
constructors = ( manage_addContentForm constructors = ( manage_addContentForm
, manage_addContent , manage_addContent
...@@ -714,7 +730,7 @@ def importLocalDocument(class_id, document_path = None): ...@@ -714,7 +730,7 @@ def importLocalDocument(class_id, document_path = None):
m[name].append(method) m[name].append(method)
m[name+'__roles__']=pr m[name+'__roles__']=pr
def initializeLocalRegistry(directory_name, import_local_method, def initializeLocalRegistry(directory_name, import_local_method,
path_arg_name='path'): path_arg_name='path'):
""" """
Initialize local directory. Initialize local directory.
...@@ -756,10 +772,15 @@ def initializeLocalConstraintRegistry(): ...@@ -756,10 +772,15 @@ def initializeLocalConstraintRegistry():
# Product initialization # Product initialization
##################################################### #####################################################
def initializeProduct( context, this_module, global_hook, def initializeProduct( context,
document_module = None, this_module,
document_classes=None, object_classes=None, portal_tools=None, global_hook,
content_constructors=None, content_classes=None): document_module=None,
document_classes=None,
object_classes=None,
portal_tools=None,
content_constructors=None,
content_classes=None):
""" """
This function does all the initialization steps required This function does all the initialization steps required
for a Zope / CMF Product for a Zope / CMF Product
...@@ -772,7 +793,6 @@ def initializeProduct( context, this_module, global_hook, ...@@ -772,7 +793,6 @@ def initializeProduct( context, this_module, global_hook,
product_name = this_module.__name__.split('.')[-1] product_name = this_module.__name__.split('.')[-1]
# Define content classes from document_classes # Define content classes from document_classes
#LOG('Begin initializeProduct %s %s' % (document_module, document_classes),0,'')
extra_content_classes = [] extra_content_classes = []
#if document_module is not None: #if document_module is not None:
if 0: if 0:
...@@ -797,9 +817,11 @@ def initializeProduct( context, this_module, global_hook, ...@@ -797,9 +817,11 @@ def initializeProduct( context, this_module, global_hook,
extra_content_constructors = [] extra_content_constructors = []
for content_class in extra_content_classes: for content_class in extra_content_classes:
if hasattr(content_class, 'add' + content_class.__name__): if hasattr(content_class, 'add' + content_class.__name__):
extra_content_constructors += [getattr(content_class, 'add' + content_class.__name__)] extra_content_constructors += [
getattr(content_class, 'add' + content_class.__name__)]
else: else:
extra_content_constructors += [getattr(document_module, 'add' + content_class.__name__)] extra_content_constructors += [
getattr(document_module, 'add' + content_class.__name__)]
# Define FactoryTypeInformations for all content classes # Define FactoryTypeInformations for all content classes
contentFactoryTypeInformations = [] contentFactoryTypeInformations = []
...@@ -812,7 +834,8 @@ def initializeProduct( context, this_module, global_hook, ...@@ -812,7 +834,8 @@ def initializeProduct( context, this_module, global_hook,
# Aggregate # Aggregate
content_classes = list(content_classes) + list(extra_content_classes) content_classes = list(content_classes) + list(extra_content_classes)
content_constructors = list(content_constructors) + list(extra_content_constructors) content_constructors = list(content_constructors)\
+ list(extra_content_constructors)
# Begin the initialization steps # Begin the initialization steps
bases = tuple(content_classes) bases = tuple(content_classes)
...@@ -824,11 +847,11 @@ def initializeProduct( context, this_module, global_hook, ...@@ -824,11 +847,11 @@ def initializeProduct( context, this_module, global_hook,
try: try:
registerDirectory('skins', global_hook) registerDirectory('skins', global_hook)
except: except:
LOG("ERP5Type:",0,"No skins directory for %s" % product_name) LOG("ERP5Type:", BLATHER, "No skins directory for %s" % product_name)
try: try:
registerDirectory('help', global_hook) registerDirectory('help', global_hook)
except: except:
LOG("ERP5Type:",0,"No help directory for %s" % product_name) LOG("ERP5Type:", BLATHER, "No help directory for %s" % product_name)
# Finish the initialization # Finish the initialization
utils.initializeBasesPhase2( z_bases, context ) utils.initializeBasesPhase2( z_bases, context )
...@@ -837,7 +860,7 @@ def initializeProduct( context, this_module, global_hook, ...@@ -837,7 +860,7 @@ def initializeProduct( context, this_module, global_hook,
if len(tools) > 0: if len(tools) > 0:
utils.ToolInit('%s Tool' % product_name, utils.ToolInit('%s Tool' % product_name,
tools=tools, tools=tools,
product_name=product_name, # product_name=product_name,
icon='tool.png', icon='tool.png',
).initialize( context ) ).initialize( context )
...@@ -848,12 +871,12 @@ def initializeProduct( context, this_module, global_hook, ...@@ -848,12 +871,12 @@ def initializeProduct( context, this_module, global_hook,
if hasattr(klass, 'permission_type'): if hasattr(klass, 'permission_type'):
klass_permission=klass.permission_type klass_permission=klass.permission_type
utils.ContentInit( klass.meta_type utils.ContentInit( klass.meta_type,
, content_types=[klass] content_types=[klass],
, permission=klass_permission permission=klass_permission,
, extra_constructors=tuple(content_constructors) extra_constructors=tuple(content_constructors),
, fti=contentFactoryTypeInformations fti=contentFactoryTypeInformations,
).initialize( context ) ).initialize( context )
# Register Help # Register Help
context.registerHelp(directory='help') context.registerHelp(directory='help')
...@@ -885,7 +908,7 @@ def createConstraintList(property_holder, constraint_definition): ...@@ -885,7 +908,7 @@ def createConstraintList(property_holder, constraint_definition):
try: try:
consistency_class = getattr(Constraint, constraint_definition['type']) consistency_class = getattr(Constraint, constraint_definition['type'])
except AttributeError: except AttributeError:
LOG("ERP5Type", 0, "Can not find Constraint: %s" % \ LOG("ERP5Type", PROBLEM, "Can not find Constraint: %s" % \
constraint_definition['type']) constraint_definition['type'])
raise raise
consistency_instance = consistency_class(**constraint_definition) consistency_instance = consistency_class(**constraint_definition)
...@@ -899,7 +922,8 @@ def initializeDefaultConstructors(klasses): ...@@ -899,7 +922,8 @@ def initializeDefaultConstructors(klasses):
for klass in klasses: for klass in klasses:
if getattr(klass, 'isRADContent', 0) and hasattr(klass, 'security'): if getattr(klass, 'isRADContent', 0) and hasattr(klass, 'security'):
setDefaultConstructor(klass) setDefaultConstructor(klass)
klass.security.declareProtected(Permissions.AddPortalContent, 'add' + klass.__name__) klass.security.declareProtected(Permissions.AddPortalContent,
'add' + klass.__name__)
def setDefaultConstructor(klass): def setDefaultConstructor(klass):
""" """
...@@ -991,12 +1015,15 @@ def setDefaultProperties(property_holder, object=None): ...@@ -991,12 +1015,15 @@ def setDefaultProperties(property_holder, object=None):
- category accessors (ie. a membership of an object to a category) - category accessors (ie. a membership of an object to a category)
- relation accessors (ie. a kind of membership where the category instance is content) - relation accessors (ie. a kind of membership where the category
instance is content)
- programmable acquisition acessors (ie. attribute accessors which are based on relations) - programmable acquisition acessors (ie. attribute accessors which
are based on relations)
Consistency checkers are intended to check the content consistency (ex. ariry of a relation) Consistency checkers are intended to check the content consistency
as well as fix content consistency through a default consistency fixing method. (ex. ariry of a relation) as well as fix content consistency
through a default consistency fixing method.
Set default attributes in current object for all properties in '_properties' Set default attributes in current object for all properties in '_properties'
""" """
...@@ -1014,16 +1041,16 @@ def setDefaultProperties(property_holder, object=None): ...@@ -1014,16 +1041,16 @@ def setDefaultProperties(property_holder, object=None):
constraint_list = [] # a list of declarative consistency definitions (ie. constraints) constraint_list = [] # a list of declarative consistency definitions (ie. constraints)
constraint_list += property_holder.__dict__.get('_constraints',[]) # Do not consider superclass _constraints definition constraint_list += property_holder.__dict__.get('_constraints',[]) # Do not consider superclass _constraints definition
for base in property_holder.property_sheets: for base in property_holder.property_sheets:
for prop in base._properties: for prop in base._properties:
# Copy the dict so that Expression objects are not overwritten. # Copy the dict so that Expression objects are not overwritten.
prop_list.append(prop.copy()) prop_list.append(prop.copy())
if hasattr(base, '_categories'): if hasattr(base, '_categories'):
if isinstance(base._categories, (tuple, list)): if isinstance(base._categories, (tuple, list)):
cat_list += base._categories cat_list += base._categories
else: else:
cat_list += [base._categories] cat_list += [base._categories]
if hasattr(base, '_constraints'): if hasattr(base, '_constraints'):
constraint_list += base._constraints constraint_list += base._constraints
# Evaluate TALES expressions. # Evaluate TALES expressions.
for prop in prop_list: for prop in prop_list:
...@@ -1051,17 +1078,20 @@ def setDefaultProperties(property_holder, object=None): ...@@ -1051,17 +1078,20 @@ def setDefaultProperties(property_holder, object=None):
converted_prop_list = [] converted_prop_list = []
converted_prop_keys = {} converted_prop_keys = {}
for prop in prop_list: for prop in prop_list:
read_permission = prop.get('read_permission', Permissions.AccessContentsInformation) read_permission = prop.get('read_permission',
Permissions.AccessContentsInformation)
if isinstance(read_permission, Expression): if isinstance(read_permission, Expression):
read_permission = read_permission(econtext) read_permission = read_permission(econtext)
write_permission = prop.get('write_permission', Permissions.ModifyPortalContent) write_permission = prop.get('write_permission',
Permissions.ModifyPortalContent)
if isinstance(write_permission, Expression): if isinstance(write_permission, Expression):
write_permission = write_permission(econtext) write_permission = write_permission(econtext)
if prop['type'] in legalTypes: if prop['type'] in legalTypes:
if 'base_id' in prop: if 'base_id' in prop:
continue continue
if not converted_prop_keys.has_key(prop['id']): if not converted_prop_keys.has_key(prop['id']):
if prop['type'] != 'content': converted_prop_list += [prop] if prop['type'] != 'content':
converted_prop_list += [prop]
converted_prop_keys[prop['id']] = 1 converted_prop_keys[prop['id']] = 1
# Create range accessors, if this has a range. # Create range accessors, if this has a range.
...@@ -1072,16 +1102,25 @@ def setDefaultProperties(property_holder, object=None): ...@@ -1072,16 +1102,25 @@ def setDefaultProperties(property_holder, object=None):
if 'storage_id' in range_prop: if 'storage_id' in range_prop:
del range_prop['storage_id'] del range_prop['storage_id']
if range_prop.get('acquisition_accessor_id', 0): if range_prop.get('acquisition_accessor_id', 0):
range_prop['acquisition_accessor_id'] = '%sRange%s' % (range_prop['acquisition_accessor_id'], value.capitalize()) range_prop['acquisition_accessor_id'] = '%sRange%s' % (
range_prop['alt_accessor_id'] = ('get' + convertToUpperCase(prop['id']),) range_prop['acquisition_accessor_id'], value.capitalize())
createDefaultAccessors(property_holder, '%s_range_%s' % (prop['id'], value), prop=range_prop, range_prop['alt_accessor_id'] = (
read_permission=read_permission, write_permission=write_permission) 'get' + convertToUpperCase(prop['id']),)
createDefaultAccessors(
property_holder,
'%s_range_%s' % (prop['id'], value),
prop=range_prop,
read_permission=read_permission,
write_permission=write_permission)
# Create translation accesor, if translatable is set # Create translation accesor, if translatable is set
if prop.get('translatable', 0): if prop.get('translatable', 0):
# make accesso like getTranslatedProperty # make accesso like getTranslatedProperty
createTranslationAccessors(property_holder, 'translated_%s' % (prop['id']), createTranslationAccessors(
read_permission=read_permission, write_permission=write_permission) property_holder,
'translated_%s' % (prop['id']),
read_permission=read_permission,
write_permission=write_permission)
# make accessor to translation_domain # make accessor to translation_domain
# first create default one as a normal property # first create default one as a normal property
txn_prop = {} txn_prop = {}
...@@ -1090,17 +1129,29 @@ def setDefaultProperties(property_holder, object=None): ...@@ -1090,17 +1129,29 @@ def setDefaultProperties(property_holder, object=None):
txn_prop['id'] = 'translation_domain' txn_prop['id'] = 'translation_domain'
txn_prop['type'] = 'string' txn_prop['type'] = 'string'
txn_prop['mode'] = 'w' txn_prop['mode'] = 'w'
createDefaultAccessors(property_holder, '%s_%s' %(prop['id'], txn_prop['id']), prop=txn_prop, createDefaultAccessors(
read_permission=read_permission, write_permission=write_permission) property_holder,
'%s_%s' %(prop['id'], txn_prop['id']),
prop=txn_prop,
read_permission=read_permission,
write_permission=write_permission)
# then overload accesors getPropertyTranslationDomain # then overload accesors getPropertyTranslationDomain
if prop.has_key('translation_domain'): if prop.has_key('translation_domain'):
default = prop['translation_domain'] default = prop['translation_domain']
else: else:
default = '' default = ''
createTranslationAccessors(property_holder, '%s_translation_domain' % (prop['id']), createTranslationAccessors(
read_permission=read_permission, write_permission=write_permission, default=default) property_holder,
createDefaultAccessors(property_holder, prop['id'], prop=prop, '%s_translation_domain' % (prop['id']),
read_permission=read_permission, write_permission=write_permission) read_permission=read_permission,
write_permission=write_permission,
default=default)
createDefaultAccessors(
property_holder,
prop['id'],
prop=prop,
read_permission=read_permission,
write_permission=write_permission)
else: else:
raise TypeError, '"%s" is illegal type for propertysheet' % \ raise TypeError, '"%s" is illegal type for propertysheet' % \
prop['type'] prop['type']
...@@ -1118,9 +1169,12 @@ def setDefaultProperties(property_holder, object=None): ...@@ -1118,9 +1169,12 @@ def setDefaultProperties(property_holder, object=None):
if cat == 'group': prop['storage_id'] = 'group' if cat == 'group': prop['storage_id'] = 'group'
elif cat == 'site': elif cat == 'site':
prop['storage_id'] = 'location' prop['storage_id'] = 'location'
createDefaultAccessors(property_holder, prop['id'], prop=prop, createDefaultAccessors(
read_permission=Permissions.AccessContentsInformation, property_holder,
write_permission=Permissions.ModifyPortalContent) prop['id'],
prop=prop,
read_permission=Permissions.AccessContentsInformation,
write_permission=Permissions.ModifyPortalContent)
# Get read and write permission # Get read and write permission
if object is not None: if object is not None:
...@@ -1128,10 +1182,14 @@ def setDefaultProperties(property_holder, object=None): ...@@ -1128,10 +1182,14 @@ def setDefaultProperties(property_holder, object=None):
else: else:
cat_object = None cat_object = None
if cat_object is not None: if cat_object is not None:
read_permission = Permissions.__dict__.get(cat_object.getReadPermission(), Permissions.AccessContentsInformation) read_permission = Permissions.__dict__.get(
cat_object.getReadPermission(),
Permissions.AccessContentsInformation)
if isinstance(read_permission, Expression): if isinstance(read_permission, Expression):
read_permission = read_permission(econtext) read_permission = read_permission(econtext)
write_permission = Permissions.__dict__.get(cat_object.getWritePermission(), Permissions.ModifyPortalContent) write_permission = Permissions.__dict__.get(
cat_object.getWritePermission(),
Permissions.ModifyPortalContent)
if isinstance(write_permission, Expression): if isinstance(write_permission, Expression):
write_permission = write_permission(econtext) write_permission = write_permission(econtext)
else: else:
...@@ -1142,7 +1200,8 @@ def setDefaultProperties(property_holder, object=None): ...@@ -1142,7 +1200,8 @@ def setDefaultProperties(property_holder, object=None):
read_permission=read_permission, write_permission=write_permission) read_permission=read_permission, write_permission=write_permission)
createValueAccessors(property_holder, cat, createValueAccessors(property_holder, cat,
read_permission=read_permission, write_permission=write_permission) read_permission=read_permission, write_permission=write_permission)
if object is not None and property_holder.__name__ == "Base": # XXX use if possible is and real class if object is not None and property_holder.__name__ == "Base":
# XXX use if possible is and real class
base_category_list = [] base_category_list = []
for cat in base_category_dict.keys(): for cat in base_category_dict.keys():
if isinstance(cat, Expression): if isinstance(cat, Expression):
...@@ -1160,10 +1219,14 @@ def setDefaultProperties(property_holder, object=None): ...@@ -1160,10 +1219,14 @@ def setDefaultProperties(property_holder, object=None):
else: else:
cat_object = None cat_object = None
if cat_object is not None: if cat_object is not None:
read_permission = Permissions.__dict__.get(cat_object.getReadPermission(), Permissions.AccessContentsInformation) read_permission = Permissions.__dict__.get(
cat_object.getReadPermission(),
Permissions.AccessContentsInformation)
if isinstance(read_permission, Expression): if isinstance(read_permission, Expression):
read_permission = read_permission(econtext) read_permission = read_permission(econtext)
write_permission = Permissions.__dict__.get(cat_object.getWritePermission(), Permissions.ModifyPortalContent) write_permission = Permissions.__dict__.get(
cat_object.getWritePermission(),
Permissions.ModifyPortalContent)
if isinstance(write_permission, Expression): if isinstance(write_permission, Expression):
write_permission = write_permission(econtext) write_permission = write_permission(econtext)
else: else:
...@@ -1175,13 +1238,15 @@ def setDefaultProperties(property_holder, object=None): ...@@ -1175,13 +1238,15 @@ def setDefaultProperties(property_holder, object=None):
# Unnecessary to create these accessors more than once. # Unnecessary to create these accessors more than once.
base_category_dict.clear() base_category_dict.clear()
# Create the constraint method list - always check type # Create the constraint method list - always check type
property_holder.constraints = [ Constraint.PropertyTypeValidity(id='type_check', property_holder.constraints = [
description="Type Validity Check Error") ] Constraint.PropertyTypeValidity(id='type_check',
description="Type Validity Check Error") ]
for const in constraint_list: for const in constraint_list:
createConstraintList(property_holder, constraint_definition=const) createConstraintList(property_holder, constraint_definition=const)
# ERP5 _properties and Zope _properties are somehow different # ERP5 _properties and Zope _properties are somehow different
# The id is converted to the Zope standard - we keep the original id as base_id # The id is converted to the Zope standard - we keep the original id
# as base_id
new_converted_prop_list = [] new_converted_prop_list = []
for prop in converted_prop_list: for prop in converted_prop_list:
new_prop = prop.copy() new_prop = prop.copy()
...@@ -1190,11 +1255,11 @@ def setDefaultProperties(property_holder, object=None): ...@@ -1190,11 +1255,11 @@ def setDefaultProperties(property_holder, object=None):
if not prop.get('base_id', None): if not prop.get('base_id', None):
new_prop['base_id'] = prop['id'] new_prop['base_id'] = prop['id']
new_prop['id'] = prop['id'] + '_list' new_prop['id'] = prop['id'] + '_list'
if prop.has_key('acquisition_base_category') and not prop.get('acquisition_copy_value'): if prop.has_key('acquisition_base_category')\
and not prop.get('acquisition_copy_value'):
# Set acquisition values as read only if no value is copied # Set acquisition values as read only if no value is copied
new_prop['mode'] = 'r' new_prop['mode'] = 'r'
new_converted_prop_list += [new_prop] new_converted_prop_list += [new_prop]
#LOG('setDefaultProperties', 0, 'property_holder = %r, object = %r, converted_prop_list = %r, new_converted_prop_list = %r' % (property_holder, object, converted_prop_list, new_converted_prop_list))
# Set the properties of the class # Set the properties of the class
property_holder._properties = tuple(new_converted_prop_list) property_holder._properties = tuple(new_converted_prop_list)
property_holder._categories = tuple(cat_list) property_holder._categories = tuple(cat_list)
...@@ -1245,7 +1310,8 @@ except: ...@@ -1245,7 +1310,8 @@ except:
##################################################### #####################################################
from Base import Base as BaseClass from Base import Base as BaseClass
from Accessor import Base, List, Object, Acquired, Content, AcquiredProperty, ContentProperty from Accessor import Base, List, Object, Acquired, Content,\
AcquiredProperty, ContentProperty
import types import types
# Compile accessors # Compile accessors
......
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