Commit eca805c4 authored by Jean-Paul Smets's avatar Jean-Paul Smets

A new accessor family is provided : Alias. The purpose of Alias accessors is...

A new accessor family is provided : Alias. The purpose of Alias accessors is to reduce the number of independent accessors and try to factorise accessors. With Aliases, overloading the default behaviour of aliases may become easier. For example, the method setFirstName will now invoke _setFirstName and then reindex. This way, an interaction method will only need to use _setFirstName  as trigger. If the user wants to overload _setFirstName , it becomes possible without having to overload setFirstName at the same time.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@15678 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 9fbcbb83
......@@ -50,15 +50,16 @@ class Accessor(Method):
def dummy_copy(self, id):
# Copy an accessor and change its id/name
#self.__call__ = None
#try:
# clone_instance = self.__class__(*self.__getinitargs__())
#except:
# LOG('dummy_copy', 0, '%r could not be generated with %r' % (id, self.__class__), error=sys.exc_info())
# raise
clone_instance = copy(self)
#delattr(self, '__call__')
#if hasattr(clone_instance, '__call__'):
# delattr(clone_instance, '__call__')
clone_instance.__name__ = id
return clone_instance
def asAlias(self, id):
# Returns an alias
from Alias import Alias
return Alias(id, self.__name__)
def asReindexAlias(self, id):
# Returns a reindexing alias
from Alias import ReindexAlias
return ReindexAlias(id, self.__name__)
\ No newline at end of file
......@@ -26,6 +26,8 @@
#
##############################################################################
import warnings
from Base import func_code, type_definition, list_types, ATTRIBUTE_PREFIX, Method
from Products.ERP5Type.PsycoWrapper import psyco
from zLOG import LOG
......@@ -160,6 +162,9 @@ class Setter(Method):
portal_type=self._portal_type[0])
instance._v_accessor_created_object = 1
if self._reindex:
warnings.warn("The reindexing accessors are deprecated.\n"
"Please use Alias.Reindex instead.",
DeprecationWarning)
o.setProperty(self._acquired_property, value, *args, **kw)
else:
o._setProperty(self._acquired_property, value, *args, **kw)
......
##############################################################################
#
# Copyright (c) 2007 Nexedi SA and Contributors. All Rights Reserved.
# Jean-Paul Smets-Solanes <jp@nexedi.com>
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsability 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
# garantees 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
##############################################################################
from Accessor import Accessor as Method
# Creation of default constructor
class func_code: pass
class Reindex(Method):
"""
Calls a given accessor and reindexes the object.
TODO: reindex property may be removed on all accessors
"""
_need__name__=1
# Generic Definition of Method Object
# This is required to call the method form the Web
# More information at http://www.zope.org/Members/htrd/howto/FunctionTemplate
func_code = func_code()
func_code.co_varnames = ('self',)
func_code.co_argcount = 1
func_defaults = ()
def __init__(self, id, accessor_id):
self._id = id
self.__name__ = id
self._accessor_id = accessor_id
def __call__(self, instance, *args, **kw):
method = getattr(instance, self._accessor_id)
method(*args, **kw)
instance.reindexObject()
class Dummy(Reindex):
"""
Calls a given accessor.
"""
_need__name__=1
# Generic Definition of Method Object
# This is required to call the method form the Web
# More information at http://www.zope.org/Members/htrd/howto/FunctionTemplate
func_code = func_code()
func_code.co_varnames = ('self',)
func_code.co_argcount = 1
func_defaults = ()
def __init__(self, id, accessor_id):
self._id = id
self.__name__ = id
self._accessor_id = accessor_id
def __call__(self, instance, *args, **kw):
method = getattr(instance, self._accessor_id)
method(*args, **kw)
\ No newline at end of file
......@@ -26,6 +26,8 @@
#
##############################################################################
import warnings
from ZPublisher.HTTPRequest import FileUpload
from TypeDefinition import type_definition, list_types, ATTRIBUTE_PREFIX
from Accessor import Accessor as Method
......@@ -91,6 +93,9 @@ class Setter(Method):
setattr(instance, self._storage_id, self._cast(args[0]))
else:
# Call the private setter
warnings.warn("The reindexing accessors are deprecated.\n"
"Please use Alias.Reindex instead.",
DeprecationWarning)
method = getattr(instance, '_' + self._id)
method(*args, **kw)
if self._reindex: instance.reindexObject() # XXX Should the Setter check
......@@ -108,13 +113,13 @@ evaluateTales = CachingMethod(_evaluateTales, id = 'evaluateTales', cache_factor
class Getter(Method):
"""
Gets an attribute value. A default value can be provided if needed.
Gets an attribute value. A default value can be provided if needed.
Note that 'default' argument is the first positional argument, this is
important if you want to override a Getter in a class, overloaded
accessors have to respect this::
getSomething(self, [default], [name=value, [name=value], ])
getSomething(self, [default], [name=value, [name=value], ])
"""
_need__name__=1
......
......@@ -26,6 +26,8 @@
#
##############################################################################
import warnings
from Base import func_code, type_definition, list_types, ATTRIBUTE_PREFIX, Method
from zLOG import LOG
from Products.ERP5Type.PsycoWrapper import psyco
......@@ -56,7 +58,11 @@ class ListSetter(Method):
portal_type=kw.get('portal_type',()),
base=kw.get('base', 0),
keep_default=0)
if self._reindex: instance.reindexObject()
if self._reindex:
warnings.warn("The reindexing accessors are deprecated.\n"
"Please use Alias.Reindex instead.",
DeprecationWarning)
instance.reindexObject()
Setter = ListSetter
......@@ -85,7 +91,11 @@ class DefaultSetter(Method):
filter=kw.get('filter', None),
portal_type=kw.get('portal_type',()),
base=kw.get('base', 0))
if self._reindex: instance.reindexObject()
if self._reindex:
warnings.warn("The reindexing accessors are deprecated.\n"
"Please use Alias.Reindex instead.",
DeprecationWarning)
instance.reindexObject()
class SetSetter(Method):
"""
......@@ -124,7 +134,11 @@ class SetSetter(Method):
portal_type=kw.get('portal_type',()),
base=kw.get('base', 0),
keep_default=1)
if self._reindex: instance.reindexObject()
if self._reindex:
warnings.warn("The reindexing accessors are deprecated.\n"
"Please use Alias.Reindex instead.",
DeprecationWarning)
instance.reindexObject()
class DefaultGetter(Method):
......
......@@ -26,6 +26,8 @@
#
##############################################################################
import warnings
from Base import func_code, type_definition, ATTRIBUTE_PREFIX, Method
import Base
from Products.ERP5Type.PsycoWrapper import psyco
......@@ -212,6 +214,9 @@ class Setter(Method):
if o is None: available_id = k
if o is not None and o.portal_type in self._portal_type:
if self._reindex:
warnings.warn("The reindexing accessors are deprecated.\n"
"Please use Alias.Reindex instead.",
DeprecationWarning)
o.setProperty(self._acquired_property, *args, **kw)
else:
o._setProperty(self._acquired_property, *args, **kw)
......@@ -222,6 +227,9 @@ class Setter(Method):
portal_type=self._portal_type[0])
instance._v_accessor_created_object = 1
if self._reindex:
warnings.warn("The reindexing accessors are deprecated.\n"
"Please use Alias.Reindex instead.",
DeprecationWarning)
o.setProperty(self._acquired_property, *args, **kw)
else:
o._setProperty(self._acquired_property, *args, **kw)
......
......@@ -26,6 +26,8 @@
#
##############################################################################
import warnings
from Base import func_code, type_definition, list_types,\
ATTRIBUTE_PREFIX, Method, evaluateTales
from TypeDefinition import asList, identity
......@@ -90,6 +92,9 @@ class DefaultSetter(Method):
setattr(instance, self._storage_id, tuple(value))
else:
# Call the private setter
warnings.warn("The reindexing accessors are deprecated.\n"
"Please use Alias.Reindex instead.",
DeprecationWarning)
method = getattr(instance, '_' + self._id)
method(*args, **kw)
if self._reindex: instance.reindexObject()
......@@ -111,6 +116,9 @@ class ListSetter(DefaultSetter):
setattr(instance, self._storage_id, tuple(value))
else:
# Call the private setter
warnings.warn("The reindexing accessors are deprecated.\n"
"Please use Alias.Reindex instead.",
DeprecationWarning)
method = getattr(instance, '_' + self._id)
method(*args, **kw)
......@@ -182,6 +190,9 @@ class SetSetter(Method):
setattr(instance, self._storage_id, tuple(new_list_value))
else:
# Call the private setter
warnings.warn("The reindexing accessors are deprecated.\n"
"Please use Alias.Reindex instead.",
DeprecationWarning)
method = getattr(instance, '_' + self._id)
method(*args, **kw)
if self._reindex: instance.reindexObject()
......
......@@ -26,6 +26,8 @@
#
##############################################################################
import warnings
from Base import func_code, type_definition, list_types, ATTRIBUTE_PREFIX, Method
from zLOG import LOG
from Products.ERP5Type.PsycoWrapper import psyco
......@@ -53,7 +55,11 @@ class SetSetter(Method):
filter=kw.get('filter', None),
portal_type=kw.get('portal_type',()),
keep_default=1)
if self._reindex: instance.reindexObject()
if self._reindex:
warnings.warn("The reindexing accessors are deprecated.\n"
"Please use Alias.Reindex instead.",
DeprecationWarning)
instance.reindexObject()
psyco.bind(__call__)
......@@ -71,7 +77,11 @@ class ListSetter(SetSetter):
filter=kw.get('filter', None),
portal_type=kw.get('portal_type',()),
keep_default=0)
if self._reindex: instance.reindexObject()
if self._reindex:
warnings.warn("The reindexing accessors are deprecated.\n"
"Please use Alias.Reindex instead.",
DeprecationWarning)
instance.reindexObject()
psyco.bind(__call__)
......@@ -90,7 +100,11 @@ class DefaultSetter(SetSetter):
spec=kw.get('spec',()),
filter=kw.get('filter', None),
portal_type=kw.get('portal_type',()))
if self._reindex: instance.reindexObject()
if self._reindex:
warnings.warn("The reindexing accessors are deprecated.\n"
"Please use Alias.Reindex instead.",
DeprecationWarning)
instance.reindexObject()
psyco.bind(__call__)
......@@ -447,7 +461,11 @@ class UidSetSetter(Method):
filter=kw.get('filter', None),
portal_type=kw.get('portal_type',()),
keep_default=1)
if self._reindex: instance.reindexObject()
if self._reindex:
warnings.warn("The reindexing accessors are deprecated.\n"
"Please use Alias.Reindex instead.",
DeprecationWarning)
instance.reindexObject()
class UidListSetter(UidSetSetter):
"""
......@@ -463,7 +481,11 @@ class UidListSetter(UidSetSetter):
filter=kw.get('filter', None),
portal_type=kw.get('portal_type',()),
keep_default=0)
if self._reindex: instance.reindexObject()
if self._reindex:
warnings.warn("The reindexing accessors are deprecated.\n"
"Please use Alias.Reindex instead.",
DeprecationWarning)
instance.reindexObject()
UidSetter = UidListSetter
......@@ -480,7 +502,11 @@ class UidDefaultSetter(UidSetSetter):
spec=kw.get('spec',()),
filter=kw.get('filter', None),
portal_type=kw.get('portal_type',()))
if self._reindex: instance.reindexObject()
if self._reindex:
warnings.warn("The reindexing accessors are deprecated.\n"
"Please use Alias.Reindex instead.",
DeprecationWarning)
instance.reindexObject()
class DefaultIdGetter(Method):
"""
......
This diff is collapsed.
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