various SyntaxErrors / missing import fixes + reorganization of the `registered` classmethod
--- a/selectors.py Tue Feb 17 12:34:13 2009 +0100
+++ b/selectors.py Tue Feb 17 12:47:07 2009 +0100
@@ -180,7 +180,7 @@
for row, rowvalue in enumerate(rset.rows):
if rowvalue[col] is None: # outer join
continue
- escore = self.score(req, rset, row, col))
+ escore = self.score(req, rset, row, col)
if not escore and not self.once_is_enough:
return 0
elif self.once_is_enough:
@@ -698,7 +698,7 @@
for i, row in enumerate(rset):
if not rset.description[i][0] in need_local_check:
continue
- if not self.score(req, rset, i, col)):
+ if not self.score(req, rset, i, col):
return 0
score += 1
return score
@@ -901,6 +901,20 @@
searchstate_accept_one = deprecated_function(searchstate_accept_one)
+def unbind_method(selector):
+ def new_selector(registered):
+ # 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
+ new_selector.__name__ = selector.__name__
+ return new_selector
+
+
+@unbind_method
def require_group_compat(registered):
def plug_selector(cls, vreg):
cls = registered(cls, vreg)
@@ -909,8 +923,9 @@
DeprecationWarning)
cls.__selectors__ += (match_user_groups(cls.require_groups),)
return cls
- return classmethod(plug_selector)
+ return plug_selector
+@unbind_method
def accepts_compat(registered):
def plug_selector(cls, vreg):
cls = registered(cls, vreg)
@@ -919,8 +934,9 @@
DeprecationWarning)
cls.__selectors__ += (implements(*cls.accepts),)
return cls
- return classmethod(plug_selector)
+ return plug_selector
+@unbind_method
def condition_compat(registered):
def plug_selector(cls, vreg):
cls = registered(cls, vreg)
@@ -929,4 +945,4 @@
DeprecationWarning)
cls.__selectors__ += (rql_condition(cls.condition),)
return cls
- return classmethod(plug_selector)
+ return plug_selector
--- a/vregistry.py Tue Feb 17 12:34:13 2009 +0100
+++ b/vregistry.py Tue Feb 17 12:47:07 2009 +0100
@@ -234,7 +234,9 @@
cls = registerer.do_it_yourself(vobjects)
#_kicked |= registerer.kicked
if cls:
- vobject = cls.registered(self)
+ # registered() is technically a classmethod but is not declared
+ # as such because we need to compose registered in some cases
+ vobject = cls.registered.im_func(cls, self)
try:
vname = vobject.__name__
except AttributeError:
--- a/web/action.py Tue Feb 17 12:34:13 2009 +0100
+++ b/web/action.py Tue Feb 17 12:47:07 2009 +0100
@@ -6,12 +6,13 @@
"""
__docformat__ = "restructuredtext en"
-from cubicweb import target
+from cubicweb import role, target
+from cubicweb.vregistry import chainall
+from cubicweb.selectors import (relation_possible, match_search_state,
+ one_line_rset, may_add_relation,
+ accepts_compat)
from cubicweb.common.appobject import AppRsetObject
from cubicweb.common.registerers import action_registerer
-from cubicweb.common.selectors import user_can_add_etype, \
- match_search_state, searchstate_accept_one
-
_ = unicode
@@ -78,11 +79,13 @@
action apply and if the logged user has access to it
"""
def my_selector(cls, req, rset, row=None, col=0, **kwargs):
- return chainall(match_search_state('normal'),
- one_line_rset,
- relation_possible(cls.rtype, role(cls), cls.etype,
- permission='add'),
- may_add_relation(cls.rtype, role(cls)))
+ selector = chainall(match_search_state('normal'),
+ one_line_rset,
+ relation_possible(cls.rtype, role(cls), cls.etype,
+ permission='add'),
+ may_add_relation(cls.rtype, role(cls)))
+ return selector(cls, req, rset, row, col, **kwargs)
+
__selectors__ = (my_selector,)
registered = accepts_compat(Action.registered.im_func)
--- a/web/box.py Tue Feb 17 12:34:13 2009 +0100
+++ b/web/box.py Tue Feb 17 12:47:07 2009 +0100
@@ -10,12 +10,12 @@
from logilab.mtconverter import html_escape
from cubicweb import Unauthorized, role as get_role
+from cubicweb.selectors import (one_line_rset, primary_view,
+ match_context_prop, has_related_entities,
+ accepts_compat, condition_compat)
from cubicweb.common.registerers import (
accepts_registerer, extresources_registerer,
etype_rtype_priority_registerer)
-from cubicweb.common.selectors import (
- one_line_rset, primary_view, match_context_prop, has_related_entities,
- accept_compat)
#etype_rtype_selector, has_relation,
from cubicweb.common.view import Template
from cubicweb.common.appobject import ReloadableMixIn
@@ -153,7 +153,7 @@
__selectors__ = (one_line_rset, primary_view,
match_context_prop,)
#etype_rtype_selector, has_relation)
- registered = accepts_compat(condition_compat(BoxTemplate.registered.im_func))
+ registered = accepts_compat(condition_compat(BoxTemplate.registered))
context = 'incontext'
def call(self, row=0, col=0, **kwargs):
--- a/web/component.py Tue Feb 17 12:34:13 2009 +0100
+++ b/web/component.py Tue Feb 17 12:47:07 2009 +0100
@@ -6,13 +6,13 @@
"""
__docformat__ = "restructuredtext en"
+from cubicweb.selectors import (paginated_rset, one_line_rset,
+ primary_view, match_context_prop,
+ condition_compat, accepts_compat)
from cubicweb.common.appobject import Component, SingletonComponent
from cubicweb.common.utils import merge_dicts
from cubicweb.common.view import VComponent, SingletonVComponent
from cubicweb.common.registerers import action_registerer
-from cubicweb.common.selectors import (paginated_rset, one_line_rset,
- primary_view, match_context_prop,
- condition_compat)
#rql_condition, accept, has_relation, etype_rtype_selector
from cubicweb.common.uilib import html_escape
--- a/web/views/basecomponents.py Tue Feb 17 12:34:13 2009 +0100
+++ b/web/views/basecomponents.py Tue Feb 17 12:47:07 2009 +0100
@@ -242,14 +242,14 @@
class RSSFeedURL(VComponent):
id = 'rss_feed_url'
- __selectors__ = (non_final_entity,)
+ __selectors__ = (non_final_entity(),)
def feed_url(self):
return self.build_url(rql=self.limited_rql(), vid='rss')
class RSSEntityFeedURL(VComponent):
id = 'rss_feed_url'
- __selectors__ = (non_final_entity, one_line_rset)
+ __selectors__ = (non_final_entity(), one_line_rset)
def feed_url(self):
return self.entity(0, 0).rss_feed_url()
--- a/web/views/schemaentities.py Tue Feb 17 12:34:13 2009 +0100
+++ b/web/views/schemaentities.py Tue Feb 17 12:47:07 2009 +0100
@@ -8,6 +8,7 @@
from logilab.mtconverter import html_escape
+from cubicweb.selectors import implements
from cubicweb.schemaviewer import SchemaViewer
from cubicweb.common.uilib import ureport_as_html
from cubicweb.common.view import EntityView
@@ -109,7 +110,7 @@
self.w(u'</em>')
-from cubicweb.web.action import EntityAction
+from cubicweb.web.action import Action
class ViewWorkflowAction(Action):
id = 'workflow'