--- a/common/selectors.py Mon Dec 22 14:31:07 2008 +0100
+++ b/common/selectors.py Mon Dec 22 17:22:54 2008 +0100
@@ -212,7 +212,7 @@
etype_form_selector = deprecated_function(accept_etype)
@lltrace
-def _nfentity_selector(cls, req, rset, row=None, col=None, **kwargs):
+def _non_final_entity(cls, req, rset, row=None, col=None, **kwargs):
"""accept non final entities
if row is not specified, use the first one
if col is not specified, use the first one
@@ -223,9 +223,10 @@
if cls.schema.eschema(etype).is_final():
return 0
return 1
+_nfentity_selector = deprecated_function(_non_final_entity)
@lltrace
-def _rqlcondition_selector(cls, req, rset, row=None, col=None, **kwargs):
+def _rql_condition(cls, req, rset, row=None, col=None, **kwargs):
"""accept single entity result set if the entity match an rql condition
"""
if cls.condition:
@@ -240,9 +241,10 @@
return 0
return 1
+_rqlcondition_selector = deprecated_function(_rql_condition)
@lltrace
-def _interface_selector(cls, req, rset, row=None, col=None, **kwargs):
+def _implement_interface(cls, req, rset, row=None, col=None, **kwargs):
"""accept uniform result sets, and apply the following rules:
* wrapped class must have a accepts_interfaces attribute listing the
@@ -294,6 +296,7 @@
return 0
score += 1
return score
+_interface_selector = deprecated_function(_implement_interface)
@lltrace
def score_entity_selector(cls, req, rset, row=None, col=None, **kwargs):
@@ -321,13 +324,14 @@
accept_rset_selector = deprecated_function(accept_rset)
@lltrace
-def but_etype_selector(cls, req, rset, row=None, col=None, **kwargs):
+def but_etype(cls, req, rset, row=None, col=None, **kwargs):
"""restrict the searchstate_accept_one_selector to exclude entity's type
refered by the .etype attribute
"""
if rset.description[row or 0][col or 0] == cls.etype:
return 0
return 1
+but_etype_selector = deprecated_function(but_etype)
@lltrace
def etype_rtype_selector(cls, req, rset, row=None, col=None, **kwargs):
@@ -347,8 +351,15 @@
return 1
@lltrace
-def accept_rtype_selector(cls, req, rset, row=None, col=None, **kwargs):
+def has_relation(cls, req, rset, row=None, col=None, **kwargs):
+ """check if the user has read access on the relations's type refered by the
+ .rtype attribute of the class, and if all entities types in the
+ result set has this relation.
+ """
if hasattr(cls, 'rtype'):
+ perm = getattr(cls, 'require_permission', 'read')
+ if not schema.rschema(cls.rtype).has_perm(req, perm):
+ return 0
if row is None:
for etype in rset.column_types(col or 0):
if not cls.relation_possible(etype):
@@ -356,13 +367,10 @@
elif not cls.relation_possible(rset.description[row][col or 0]):
return 0
return 1
+accept_rtype_selector = deprecated_function(has_relation)
@lltrace
-def has_related_entities(cls, req, rset, row=None, col=None, **kwargs):
- return bool(rset.get_entity(row or 0, col or 0).related(cls.rtype, role(cls)))
-
-@lltrace
-def one_has_relation_selector(cls, req, rset, row=None, col=None, **kwargs):
+def one_has_relation(cls, req, rset, row=None, col=None, **kwargs):
"""check if the user has read access on the relations's type refered by the
.rtype attribute of the class, and if at least one entity type in the
result set has this relation.
@@ -378,6 +386,12 @@
elif cls.relation_possible(rset.description[row][col or 0]):
return 1
return 0
+one_has_relation_selector = deprecated_function(one_has_relation)
+
+@lltrace
+def has_related_entities(cls, req, rset, row=None, col=None, **kwargs):
+ return bool(rset.get_entity(row or 0, col or 0).related(cls.rtype, role(cls)))
+
@lltrace
def match_user_group(cls, req, rset=None, row=None, col=None, **kwargs):
@@ -448,25 +462,32 @@
# compound selectors ##########################################################
-nfentity_selector = chainall(nonempty_rset, _nfentity_selector)
+non_final_entity = chainall(nonempty_rset, _non_final_entity)
+nfentity_selector = deprecated_function(non_final_entity)
-implement_interface = chainall(nfentity_selector, _interface_selector)
+implement_interface = chainall(non_final_entity, _implement_interface)
interface_selector = deprecated_function(implement_interface)
-accept = chainall(nfentity_selector, accept_rset_selector)
+accept = chainall(non_final_entity, accept_rset)
accept_selector = deprecated_function(accept)
-accept_one_selector = chainall(one_line_rset, accept_selector)
+accept_one = chainall(one_line_rset, accept_selector)
+accept_one_selector = deprecated_function(accept_one)
-rqlcondition_selector = chainall(nfentity_selector, one_line_rset,
- _rqlcondition_selector)
+rql_condition = chainall(non_final_entity, one_line_rset, _rql_condition)
+rqlcondition_selector = deprecated_function(rql_condition)
+
-searchstate_accept_selector = chainall(nonempty_rset, searchstate_selector,
- accept_selector)
-searchstate_accept_one_selector = chainall(nonempty_rset, searchstate_selector,
- accept_selector, rqlcondition_selector)
-searchstate_accept_one_but_etype_selector = chainall(searchstate_accept_one_selector,
- but_etype_selector)
+searchstate_accept = chainall(nonempty_rset, match_search_state, accept)
+searchstate_accept_selector = deprecated_function(searchstate_accept)
+
+searchstate_accept_one = chainall(one_line_rset, match_search_state,
+ accept, _rql_condition)
+searchstate_accept_one_selector = deprecated_function(searchstate_accept_one)
+
+searchstate_accept_one_but_etype = chainall(searchstate_accept_one, but_etype)
+searchstate_accept_one_but_etype_selector = deprecated_function(
+ searchstate_accept_one_but_etype)
#__all__ = [name for name in globals().keys() if name.endswith('selector')]
#__all__ += ['chainall', 'chainfirst']
--- a/goa/appobjects/components.py Mon Dec 22 14:31:07 2008 +0100
+++ b/goa/appobjects/components.py Mon Dec 22 17:22:54 2008 +0100
@@ -14,7 +14,7 @@
from cubicweb import typed_eid
from cubicweb.schema import display_name
from cubicweb.common.view import StartupView, EntityView
-from cubicweb.common.selectors import (one_line_rset, searchstate_selector,
+from cubicweb.common.selectors import (one_line_rset, match_search_state,
accept_selector)
from cubicweb.web import Redirect
from cubicweb.web.views import vid_from_rset
@@ -31,7 +31,7 @@
"""
id = 'search-associate'
- __selectors__ = (one_line_rset, searchstate_selector, accept_selector)
+ __selectors__ = (one_line_rset, match_search_state, accept_selector)
accepts = ('Any',)
search_states = ('linksearch',)
--- a/web/action.py Mon Dec 22 14:31:07 2008 +0100
+++ b/web/action.py Mon Dec 22 17:22:54 2008 +0100
@@ -9,8 +9,8 @@
from cubicweb.common.appobject import AppRsetObject
from cubicweb.common.registerers import action_registerer
from cubicweb.common.selectors import add_etype_selector, \
- searchstate_selector, searchstate_accept_one_selector, \
- searchstate_accept_one_but_etype_selector
+ match_search_state, searchstate_accept_one, \
+ searchstate_accept_one_but_etype
_ = unicode
@@ -21,7 +21,7 @@
"""
__registry__ = 'actions'
__registerer__ = action_registerer
- __selectors__ = (searchstate_selector,)
+ __selectors__ = (match_search_state,)
# by default actions don't appear in link search mode
search_states = ('normal',)
property_defs = {
@@ -115,7 +115,7 @@
"""link to the entity creation form. Concrete class must set .etype and
may override .vid
"""
- __selectors__ = (add_etype_selector, searchstate_selector)
+ __selectors__ = (add_etype_selector, match_search_state)
vid = 'creation'
etype = None
@@ -127,7 +127,7 @@
"""an action for an entity. By default entity actions are only
displayable on single entity result if accept match.
"""
- __selectors__ = (searchstate_accept_one_selector,)
+ __selectors__ = (searchstate_accept_one,)
schema_action = None
condition = None
@@ -217,5 +217,5 @@
"""LinkToEntity action where the action is not usable on the same
entity's type as the one refered by the .etype attribute
"""
- __selectors__ = (searchstate_accept_one_but_etype_selector,)
+ __selectors__ = (searchstate_accept_one_but_etype,)
--- a/web/views/actions.py Mon Dec 22 14:31:07 2008 +0100
+++ b/web/views/actions.py Mon Dec 22 17:22:54 2008 +0100
@@ -23,7 +23,7 @@
if accept match.
"""
category = 'mainactions'
- __selectors__ = (searchstate_accept_selector,)
+ __selectors__ = (searchstate_accept,)
search_states = ('linksearch',)
order = 0
@@ -54,7 +54,7 @@
class ViewAction(Action):
category = 'mainactions'
- __selectors__ = (in_group_selector, searchstate_accept_selector)
+ __selectors__ = (in_group_selector, searchstate_accept)
require_groups = ('users', 'managers')
order = 0
@@ -78,8 +78,8 @@
class ModifyAction(EntityAction):
category = 'mainactions'
- __selectors__ = (one_line_rset, searchstate_accept_selector)
- #__selectors__ = searchstate_accept_selector,
+ __selectors__ = (one_line_rset, searchstate_accept)
+ #__selectors__ = searchstate_accept,
schema_action = 'update'
order = 10
@@ -106,7 +106,7 @@
class DeleteAction(EntityAction):
category = 'moreactions'
- __selectors__ = (searchstate_accept_selector,)
+ __selectors__ = (searchstate_accept,)
schema_action = 'delete'
order = 20
@@ -136,7 +136,7 @@
class MultipleEditAction(EntityAction):
category = 'mainactions'
__selectors__ = (two_lines_rset, oneetyperset_selector,
- searchstate_accept_selector)
+ searchstate_accept)
schema_action = 'update'
order = 10
@@ -171,7 +171,7 @@
if not eschema.is_final() and eschema.has_perm(req, 'add'):
return 1
return 0
- __selectors__ = (searchstate_selector,
+ __selectors__ = (match_search_state,
chainfirst(etype_rset_selector,
chainall(two_lines_rset, oneetyperset_selector,
has_add_perm_selector)))
--- a/web/views/baseviews.py Mon Dec 22 14:31:07 2008 +0100
+++ b/web/views/baseviews.py Mon Dec 22 17:22:54 2008 +0100
@@ -22,7 +22,7 @@
from cubicweb import Unauthorized, NoSelectableObject, typed_eid
from cubicweb.common.selectors import (yes, nonempty_rset, accept_selector,
- one_line_rset, searchstate_selector,
+ one_line_rset, match_search_state,
req_form_params_selector, accept_rset_selector)
from cubicweb.common.uilib import (cut, printable_value, UnicodeCSVWriter,
ajax_replace_url, rql_for_eid)
@@ -760,7 +760,7 @@
"""
id = 'search-associate'
title = _('search for association')
- __selectors__ = (one_line_rset, searchstate_selector, accept_selector)
+ __selectors__ = (one_line_rset, match_search_state, accept_selector)
accepts = ('Any',)
search_states = ('linksearch',)
--- a/web/views/embedding.py Mon Dec 22 14:31:07 2008 +0100
+++ b/web/views/embedding.py Mon Dec 22 17:22:54 2008 +0100
@@ -18,7 +18,7 @@
from cubicweb.interfaces import IEmbedable
from cubicweb.common.uilib import soup2xhtml
from cubicweb.common.selectors import (one_line_rset, score_entity_selector,
- searchstate_selector, interface_selector)
+ match_search_state, interface_selector)
from cubicweb.common.view import NOINDEX, NOFOLLOW
from cubicweb.web.controller import Controller
from cubicweb.web.action import Action
@@ -81,7 +81,7 @@
"""
id = 'embed'
controller = 'embed'
- __selectors__ = (one_line_rset, searchstate_selector,
+ __selectors__ = (one_line_rset, match_search_state,
interface_selector, score_entity_selector)
accepts_interfaces = (IEmbedable,)