Commit d94d7da3 authored by Nicolas Dumazet's avatar Nicolas Dumazet

Move up all temporary-related code to a new ERP5Type mixin.

In particular, remove the hackish _set_xxx on Base


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@43006 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 3d10c701
......@@ -3280,44 +3280,6 @@ class Base( CopyContainer,
from Products.ERP5Type.Error import Error
return Error(**kw)
_temp_isIndexable = 0
def _temp_reindexObject(self, *args, **kw):
pass
def _temp_recursiveReindexObject(self, *args, **kw):
pass
def _temp_activate(self, *args, **kw):
return self
def _temp_setUid(self, value):
self.uid = value # Required for Listbox so that no casting happens when we use TempBase to create new objects
def _temp_getUid(self):
try:
return getattr(aq_base(self), 'uid')
except AttributeError:
value = self.getId()
self.setUid(value)
return value
def _temp_setTitle(self, value):
"""
Required so that getProperty('title') will work on tempBase objects
The dynamic acquisition work very well for a lot of properties, but
not for title. For example, if we do setProperty('organisation_url'), then
even if organisation_url is not in a propertySheet, the method getOrganisationUrl
will be generated. But this does not work for title, because I(seb)'m almost sure
there is somewhere a method '_setTitle' or 'setTitle' with no method getTitle on Base.
That why setProperty('title') and getProperty('title') does not work.
"""
self.title = value
def _temp_getTitle(self):
return getattr(self,'title',None)
security.declarePublic('log')
def log(self, description, content='', level=INFO):
"""Put a log message """
......
......@@ -35,6 +35,8 @@ from types import ModuleType
from dynamic_module import registerDynamicModule
from accessor_holder import _generateBaseAccessorHolder, _generatePreferenceToolAccessorHolder
from Products.ERP5Type.mixin.temporary import TemporaryDocumentMixin
from Products.ERP5Type.Base import _aq_reset, Base
from Products.ERP5Type.Globals import InitializeClass
from Products.ERP5Type.Utils import setDefaultClassProperties
......@@ -389,26 +391,8 @@ def initializeDynamicModules():
"""
klass = getattr(portal_type_container, portal_type_name)
from Products.ERP5Type.Accessor.Constant import PropertyGetter as \
PropertyConstantGetter
class TempDocument(klass):
isTempDocument = PropertyConstantGetter('isTempDocument', value=True)
__roles__ = None
TempDocument.__name__ = "Temp " + portal_type_name
# Replace some attributes.
for name in ('isIndexable', 'reindexObject', 'recursiveReindexObject',
'activate', 'setUid', 'setTitle', 'getTitle', 'getUid'):
setattr(TempDocument, name, getattr(klass, '_temp_%s' % name))
# Make some methods public.
for method_id in ('reindexObject', 'recursiveReindexObject',
'activate', 'setUid', 'setTitle', 'getTitle',
'edit', 'setProperty', 'getUid', 'setCriterion',
'setCriterionPropertyList'):
setattr(TempDocument, '%s__roles__' % method_id, None)
return TempDocument
return type("Temporary %s" % portal_type_name,
(TemporaryDocumentMixin, klass), {})
erp5.temp_portal_type = registerDynamicModule('erp5.temp_portal_type',
loadTempPortalTypeClass)
......
##############################################################################
#
# Copyright (c) 2010 Nexedi SARL and Contributors. All Rights Reserved.
# Nicolas Dumazet <nicolas.dumazet@nexedi.com>
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsibility of assessing all potential
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
# guarantees and support are strongly adviced to contract a Free Software
# Service Company
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
##############################################################################
from Acquisition import aq_base
from Products.ERP5Type.Accessor.Constant import PropertyGetter as \
PropertyConstantGetter
class TemporaryDocumentMixin(object):
"""
Setters and attributes that are attached to temporary documents.
"""
isIndexable = 0
isTempDocument = PropertyConstantGetter('isTempDocument', value=True)
__roles__ = None
def reindexObject(self, *args, **kw):
pass
def recursiveReindexObject(self, *args, **kw):
pass
def activate(self, *args, **kw):
return self
def setUid(self, value):
self.uid = value # Required for Listbox so that no casting happens when we use TempBase to create new objects
def getUid(self):
try:
return getattr(aq_base(self), 'uid')
except AttributeError:
value = self.getId()
self.setUid(value)
return value
def setTitle(self, value):
"""
Required so that getProperty('title') will work on tempBase objects
The dynamic acquisition work very well for a lot of properties, but
not for title. For example, if we do setProperty('organisation_url'), then
even if organisation_url is not in a propertySheet, the method getOrganisationUrl
will be generated. But this does not work for title, because I(seb)'m almost sure
there is somewhere a method '_setTitle' or 'setTitle' with no method getTitle on Base.
That why setProperty('title') and getProperty('title') does not work.
"""
self.title = value
def getTitle(self):
return getattr(self,'title',None)
# Make some methods public.
for method_id in ('reindexObject', 'recursiveReindexObject',
'activate', 'setUid', 'setTitle', 'getTitle',
'edit', 'setProperty', 'getUid', 'setCriterion',
'setCriterionPropertyList'):
setattr(TemporaryDocumentMixin, '%s__roles__' % method_id, None)
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