Commit c21d6c56 authored by Sylvain Thénault's avatar Sylvain Thénault
Browse files

reorganize, cleanup and properly document base selectors. Kill the may_add_relation selector.

parent a35c76ffed92
......@@ -27,7 +27,7 @@ def objectify_selector(selector_func):
would be overkill::
@objectify_selector
def yes(cls, *args, **kwargs):
def one(cls, *args, **kwargs):
return 1
"""
......@@ -185,9 +185,13 @@ class NotSelector(Selector):
class yes(Selector):
"""return arbitrary score
"""Return the score given as parameter, with a default score of 0.5 so any
other selector take precedence.
default score of 0.5 so any other selector take precedence
Usually used for appobjects which can be selected whatever the context, or
also sometimes to add arbitrary points to a score.
Take care, `yes(0)` could be named 'no'...
"""
def __init__(self, score=0.5):
self.score = score
......
This diff is collapsed.
......@@ -10,7 +10,7 @@ _ = unicode
from cubicweb import target
from cubicweb.selectors import (partial_relation_possible, match_search_state,
one_line_rset, partial_may_add_relation, yes)
one_line_rset, yes)
from cubicweb.appobject import AppObject
......@@ -76,22 +76,28 @@ class UnregisteredAction(Action):
class LinkToEntityAction(Action):
"""base class for actions consisting to create a new object
with an initial relation set to an entity.
Additionaly to EntityAction behaviour, this class is parametrized
using .etype, .rtype and .target attributes to check if the
action apply and if the logged user has access to it
"""base class for actions consisting to create a new object with an initial
relation set to an entity.
Additionaly to EntityAction behaviour, this class is parametrized using
.rtype, .role and .target_etype attributes to check if the action apply and
if the logged user has access to it (see
:class:`~cubicweb.selectors.partial_relation_possible` selector
documentation for more information).
"""
__select__ = (match_search_state('normal') & one_line_rset()
& partial_relation_possible(action='add')
& partial_may_add_relation())
& partial_relation_possible(action='add', strict=True))
submenu = 'addrelated'
def url(self):
current_entity = self.cw_rset.get_entity(self.cw_row or 0, self.cw_col or 0)
linkto = '%s:%s:%s' % (self.rtype, current_entity.eid, target(self))
return self._cw.build_url('add/%s' % self.etype, __linkto=linkto,
__redirectpath=current_entity.rest_path(), # should not be url quoted!
try:
ttype = self.etype # deprecated in 3.6, already warned by the selector
except AttributeError:
ttype = self.target_etype
entity = self.cw_rset.get_entity(self.cw_row or 0, self.cw_col or 0)
linkto = '%s:%s:%s' % (self.rtype, entity.eid, target(self))
return self._cw.build_url('add/%s' % ttype, __linkto=linkto,
__redirectpath=entity.rest_path(),
__redirectvid=self._cw.form.get('__redirectvid', ''))
......@@ -211,7 +211,7 @@ class AddNewAction(MultipleEditAction):
__regid__ = 'addentity'
__select__ = (action.Action.__select__ &
(addable_etype_empty_rset()
| (multi_lines_rset() & one_etype_rset & has_add_permission()))
| (multi_lines_rset() & one_etype_rset() & has_add_permission()))
)
category = 'moreactions'
......
Supports Markdown
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