# HG changeset patch # User Adrien Di Mascio # Date 1234874938 -3600 # Node ID fd019f41aa2ff602cc1c1ef2205da551c74c2c44 # Parent 3f2956c186efd993817b8bfaeaa52955cd0079ca work in progress - fix deprecation of EntityAction - fix various selectors bugs diff -r 3f2956c186ef -r fd019f41aa2f selectors.py --- a/selectors.py Tue Feb 17 13:44:31 2009 +0100 +++ b/selectors.py Tue Feb 17 13:48:58 2009 +0100 @@ -556,12 +556,12 @@ self.action = action @lltrace - def __call__(self, cls, *args, **kwargs): + def __call__(self, cls, req, *args, **kwargs): rschema = cls.schema.rschema(self.rtype) if not (rschema.has_perm(req, self.action) or rschema.has_local_role(self.action)): return 0 - return super(relation_possible, self)(cls, *args, **kwargs) + return super(relation_possible, self).__call__(cls, req, *args, **kwargs) def score_class(self, eclass, req): eschema = eclass.e_schema @@ -906,14 +906,22 @@ # get the unbound method if hasattr(registered, 'im_func'): registered = registered.im_func - return selector(registered) # don't rebind since it will be done automatically during # the assignment, inside the destination class body - return plugged_selector + return selector(registered) new_selector.__name__ = selector.__name__ return new_selector +def deprecate(registered, msg): + # get the unbound method + if hasattr(registered, 'im_func'): + registered = registered.im_func + def _deprecate(cls, vreg): + warn(msg, DeprecationWarning) + return registered(cls, vreg) + return _deprecate + @unbind_method def require_group_compat(registered): def plug_selector(cls, vreg): diff -r 3f2956c186ef -r fd019f41aa2f web/action.py --- a/web/action.py Tue Feb 17 13:44:31 2009 +0100 +++ b/web/action.py Tue Feb 17 13:48:58 2009 +0100 @@ -10,8 +10,8 @@ from cubicweb import role, target from cubicweb.selectors import (relation_possible, match_search_state, - one_line_rset, may_add_relation, - accepts_compat) + one_line_rset, may_add_relation, yes, + accepts_compat, condition_compat, deprecate) from cubicweb.common.appobject import AppRsetObject from cubicweb.common.registerers import action_registerer @@ -24,7 +24,8 @@ """ __registry__ = 'actions' __registerer__ = action_registerer - + __selectors__ = (yes,) + property_defs = { 'visible': dict(type='Boolean', default=True, help=_('display the action or not')), @@ -93,7 +94,10 @@ __redirectpath=current_entity.rest_path(), # should not be url quoted! __redirectvid=self.req.form.get('__redirectvid', '')) - -EntityAction = class_moved('EntityAction', Action, - 'EntityAction is deprecated, use Action with appropriate selectors') +class EntityAction(Action): + """DEPRECATED / BACKWARD COMPAT + """ + registered = deprecate(accepts_compat(condition_compat(Action.registered)), + msg='EntityAction is deprecated, use Action with ' + 'appropriate selectors')