--- a/common/view.py Mon Feb 16 20:06:18 2009 +0100
+++ b/common/view.py Mon Feb 16 20:51:24 2009 +0100
@@ -8,7 +8,6 @@
__docformat__ = "restructuredtext en"
from cStringIO import StringIO
-from warnings import warn
from logilab.mtconverter import html_escape
@@ -297,18 +296,6 @@
def create_url(self, etype, **kwargs):
""" return the url of the entity creation form for a given entity type"""
return self.req.build_url('add/%s'%etype, **kwargs)
-
-
-# concrete views base classes #################################################
-
-class EntityView(View):
- """base class for views applying on an entity (i.e. uniform result set)
- """
- __registerer__ = accepts_registerer
- __selectors__ = (implements('Any'),)
- registered = accepts_compat(View.registered.im_func)
-
- category = 'entityview'
def field(self, label, value, row=True, show_label=True, w=None, tr=True):
""" read-only field """
@@ -325,6 +312,19 @@
w(u'</div>')
+# concrete views base classes #################################################
+
+class EntityView(View):
+ """base class for views applying on an entity (i.e. uniform result set)
+ """
+ # XXX deprecate
+ __registerer__ = accepts_registerer
+ __selectors__ = (implements('Any'),)
+ registered = accepts_compat(View.registered.im_func)
+
+ category = 'entityview'
+
+
class StartupView(View):
"""base class for views which doesn't need a particular result set
to be displayed (so they can always be displayed !)
--- a/selectors.py Mon Feb 16 20:06:18 2009 +0100
+++ b/selectors.py Mon Feb 16 20:51:24 2009 +0100
@@ -324,7 +324,7 @@
if rowvalue[col] is None: # outer join
continue
try:
- escore = self.score_entity(rset.get_entity(row, col))
+ escore = self.score(req, rset, row, col))
except NotAnEntity:
return 0
if not escore:
@@ -333,12 +333,15 @@
else:
etype = rset.description[row][col]
if etype is not None: # outer join
- try:
- score = self.score_entity(rset.get_entity(row, col))
- except NotAnEntity:
- return 0
+ score = self.score(req, rset, row, col)
return score and (score + 1)
+ def score(self, req, rset, row, col):
+ try:
+ return self.score_entity(rset.get_entity(row, col))
+ except NotAnEntity:
+ return 0
+
def score_entity(self, entity):
raise NotImplementedError()
@@ -612,26 +615,23 @@
def __init__(self, scorefunc):
self.score_entity = scorefunc
-
-# XXX not so basic selectors ######################################################
-@lltrace
-def _rql_condition(cls, req, rset, row=None, col=0, **kwargs):
- """accept single entity result set if the entity match an rql condition
- """
- if cls.condition:
- eid = rset[row or 0][col or 0]
+class rql_condition(EntitySelector):
+ def __init__(self, expression):
if 'U' in frozenset(split_expression(cls.condition)):
- rql = 'Any X WHERE X eid %%(x)s, U eid %%(u)s, %s' % cls.condition
+ rql = 'Any X WHERE X eid %%(x)s, U eid %%(u)s, %s' % expression
else:
- rql = 'Any X WHERE X eid %%(x)s, %s' % cls.condition
+ rql = 'Any X WHERE X eid %%(x)s, %s' % expression
+ self.rql = rql
+
+ def score(self, req, rset, row, col):
try:
- return len(req.execute(rql, {'x': eid, 'u': req.user.eid}, 'x'))
+ return len(req.execute(self.rql, {'x': eid, 'u': req.user.eid}, 'x'))
except Unauthorized:
return 0
- return 1
-_rqlcondition_selector = deprecated_function(_rql_condition)
+
+# XXX not so basic selectors ######################################################
@lltrace
def but_etype(cls, req, rset, row=None, col=0, **kwargs):
@@ -757,16 +757,25 @@
accept_selector = deprecated_function(accept)
accept = deprecated_function(accept, 'use implements selector')
-# compound selectors ##########################################################
-
accept_one = deprecated_function(chainall(one_line_rset, accept,
name='accept_one'))
accept_one_selector = deprecated_function(accept_one)
-rql_condition = chainall(non_final_entity(), one_line_rset, _rql_condition,
- name='rql_condition')
-rqlcondition_selector = deprecated_function(rql_condition)
+
+@lltrace
+def _rql_condition(cls, req, rset, row=None, col=0, **kwargs):
+ if cls.condition:
+ return rql_condition(cls.condition)(cls, req, rset, row, col)
+ return 1
+_rqlcondition_selector = deprecated_function(_rql_condition)
+rqlcondition_selector = deprecated_function(chainall(non_final_entity(), one_line_rset, _rql_condition,
+ name='rql_condition'))
+
+#req_form_params_selector = deprecated_function(match_form_params) # form_params
+#kwargs_selector = deprecated_function(match_kwargs) # expected_kwargs
+
+# compound selectors ##########################################################
searchstate_accept = chainall(nonempty_rset, match_search_state, accept,
name='searchstate_accept')
@@ -782,9 +791,6 @@
searchstate_accept_one_but_etype_selector = deprecated_function(
searchstate_accept_one_but_etype)
-#req_form_params_selector = deprecated_function(match_form_params) # form_params
-#kwargs_selector = deprecated_function(match_kwargs) # expected_kwargs
-
def require_group_compat(registered):
def plug_selector(cls, vreg):
@@ -805,3 +811,13 @@
cls.__selectors__ += (implements(*cls.accepts),)
return cls
return classmethod(plug_selector)
+
+def condition_compat(registered):
+ def plug_selector(cls, vreg):
+ cls = registered(cls, vreg)
+ if getattr(cls, 'condition', None):
+ warn('use "use rql_condition(expression)" instead of using condition',
+ DeprecationWarning)
+ cls.__selectors__ += (rql_condition(cls.condition),)
+ return cls
+ return classmethod(plug_selector)
--- a/web/action.py Mon Feb 16 20:06:18 2009 +0100
+++ b/web/action.py Mon Feb 16 20:51:24 2009 +0100
@@ -83,7 +83,7 @@
# XXX deprecate
-class LinkToEntityAction(EntityAction):
+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
@@ -92,11 +92,12 @@
"""
def my_selector(cls, req, rset, row=None, col=0, **kwargs):
return chainall(match_search_state('normal'),
- one_line_rset, accept,
+ one_line_rset,
relation_possible(cls.rtype, role(cls), cls.etype,
permission='add'),
may_add_relation(cls.rtype, role(cls)))
- __selectors__ = my_selector,
+ __selectors__ = (my_selector,)
+ registered = accepts_compat(Action.registered.im_func)
category = 'addrelated'
--- a/web/box.py Mon Feb 16 20:06:18 2009 +0100
+++ b/web/box.py Mon Feb 16 20:51:24 2009 +0100
@@ -1,7 +1,7 @@
"""abstract box classes for CubicWeb web client
:organization: Logilab
-:copyright: 2001-2008 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
+:copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
"""
__docformat__ = "restructuredtext en"
@@ -14,9 +14,9 @@
accepts_registerer, extresources_registerer,
etype_rtype_priority_registerer)
from cubicweb.common.selectors import (
- etype_rtype_selector, one_line_rset, accept, has_relation,
- primary_view, match_context_prop, has_related_entities,
- _rql_condition)
+ 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
@@ -106,7 +106,7 @@
user's rights) and rql attributes
"""
__registerer__ = etype_rtype_priority_registerer
- __selectors__ = BoxTemplate.__selectors__ + (etype_rtype_selector,)
+#XXX __selectors__ = BoxTemplate.__selectors__ + (etype_rtype_selector,)
rql = None
@@ -151,11 +151,10 @@
"""base class for boxes related to a single entity"""
__registerer__ = accepts_registerer
__selectors__ = (one_line_rset, primary_view,
- match_context_prop, etype_rtype_selector,
- has_relation, accept, _rql_condition)
- accepts = ('Any',)
+ match_context_prop,)
+ #etype_rtype_selector, has_relation)
+ registered = accepts_compat(condition_compat(BoxTemplate.registered.im_func))
context = 'incontext'
- condition = None
def call(self, row=0, col=0, **kwargs):
"""classes inheriting from EntityBoxTemplate should define cell_call"""
--- a/web/component.py Mon Feb 16 20:06:18 2009 +0100
+++ b/web/component.py Mon Feb 16 20:51:24 2009 +0100
@@ -1,7 +1,7 @@
"""abstract component class and base components definition for CubicWeb web client
:organization: Logilab
-:copyright: 2001-2008 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
+:copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
"""
__docformat__ = "restructuredtext en"
@@ -11,9 +11,9 @@
from cubicweb.common.view import VComponent, SingletonVComponent
from cubicweb.common.registerers import action_registerer
from cubicweb.common.selectors import (paginated_rset, one_line_rset,
- rql_condition, accept, primary_view,
- match_context_prop, has_relation,
- etype_rtype_selector)
+ primary_view, match_context_prop,
+ condition_compat)
+#rql_condition, accept, has_relation, etype_rtype_selector
from cubicweb.common.uilib import html_escape
_ = unicode
@@ -33,9 +33,12 @@
__registry__ = 'contentnavigation'
__registerer__ = action_registerer
__selectors__ = (one_line_rset, primary_view,
- match_context_prop, etype_rtype_selector,
- has_relation, accept,
- rql_condition)
+ match_context_prop,
+# etype_rtype_selector,
+# has_relation, accept,
+# rql_condition)
+ )
+ registered = accepts_compat(condition_compat(VComponent.registered.im_func))
property_defs = {
_('visible'): dict(type='Boolean', default=True,
@@ -51,9 +54,7 @@
help=_('html class of the component')),
}
- accepts = ('Any',)
context = 'navcontentbottom' # 'footer' | 'header' | 'incontext'
- condition = None
def call(self, view):
return self.cell_call(0, 0, view)
@@ -152,8 +153,10 @@
class RelatedObjectsVComponent(EntityVComponent):
"""a section to display some related entities"""
__selectors__ = (one_line_rset, primary_view,
- etype_rtype_selector, has_relation,
- match_context_prop, accept)
+ match_context_prop,
+# etype_rtype_selector, has_relation,
+# accept)
+ )
vid = 'list'
def rql(self):
--- a/web/views/massmailing.py Mon Feb 16 20:06:18 2009 +0100
+++ b/web/views/massmailing.py Mon Feb 16 20:51:24 2009 +0100
@@ -1,7 +1,7 @@
"""Mass mailing form views
:organization: Logilab
-:copyright: 2007-2008 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
+:copyright: 2007-2009 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
"""
@@ -12,11 +12,11 @@
from cubicweb.interfaces import IEmailable
from cubicweb.selectors import implements, match_user_groups
from cubicweb.common.view import EntityView
-from cubicweb.web.action import EntityAction
+from cubicweb.web.action import Action
from cubicweb.web import stdmsgs
-class SendEmailAction(EntityAction):
+class SendEmailAction(Action):
category = 'mainactions'
# XXX should check email is set as well
__selectors__ = (implements(IEmailable), match_user_groups('managers', 'users'))
--- a/web/views/schemaentities.py Mon Feb 16 20:06:18 2009 +0100
+++ b/web/views/schemaentities.py Mon Feb 16 20:51:24 2009 +0100
@@ -111,8 +111,10 @@
from cubicweb.web.action import EntityAction
-class ViewWorkflowAction(EntityAction):
+class ViewWorkflowAction(Action):
id = 'workflow'
+ __selectors__ = (implements('EEType'), )
+
category = 'mainactions'
title = _('view workflow')
accepts = ('EEType',)