more selectors update
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Wed, 24 Jun 2009 15:27:09 +0200
changeset 36 a740df377315
parent 35 3fcc5ce85e14
child 37 eecf61767e2a
more selectors update
hooks.py
views.py
--- a/hooks.py	Wed Jun 24 15:26:36 2009 +0200
+++ b/hooks.py	Wed Jun 24 15:27:09 2009 +0200
@@ -7,10 +7,12 @@
 
 from logilab.common.decorators import cached
 
-from cubicweb.common import ValidationError
+from cubicweb import ValidationError
+from cubicweb.selectors import implements
 from cubicweb.server.hooksmanager import Hook
 from cubicweb.server.pool import PreCommitOperation
-from cubicweb.sobjects.notification import ContentAddedView, NotificationView, StatusChangeMixIn
+from cubicweb.sobjects.notification import (ContentAddedView, NotificationView,
+                                            StatusChangeMixIn)
 
 class BeforeKeywordApplicationHook(Hook):
     """
@@ -80,7 +82,7 @@
 
 
 class KeywordNotificationView(NotificationView):
-    accepts = ('Keyword',)
+    __select__ = implements('Keyword')
     msgid_timestamp = True
 
     def recipients(self):
@@ -136,7 +138,7 @@
 
 class KeywordAddedView(ContentAddedView):
     """get notified from new keywords"""
-    accepts = ('Keyword',)
+    __select__ = implements('Keyword')
     content_attr = 'name'
     msgid_timestamp = True
 
--- a/views.py	Wed Jun 24 15:26:36 2009 +0200
+++ b/views.py	Wed Jun 24 15:27:09 2009 +0200
@@ -11,7 +11,7 @@
 from logilab.common.decorators import monkeypatch
 from logilab.mtconverter import html_escape
 
-from cubicweb.selectors import implements, rql_condition
+from cubicweb.selectors import implements, rql_condition, relation_possible
 from cubicweb.view import EntityView
 from cubicweb.common.mixins import TreePathMixIn
 from cubicweb.web import stdmsgs, uicfg, component
@@ -66,13 +66,10 @@
 # keyword component ###########################################################
 
 class KeywordBarVComponent(component.EntityVComponent):
-    """the keywords path bar: display keywords of a tagged entity
-    """
+    """the keywords path bar: display keywords of a tagged entity"""
     id = 'keywordsbar'
-    etype = 'Keyword'
-    rtype = 'applied_to'
-    target = 'subject'
-    #require_permission = 'read'
+    __select__ = component.EntityVComponent.__select__ & \
+                 relation_possible('applied_to', 'object', 'Keyword')
     context = 'header'
     order = 152
     htmlclass = 'navigation'
@@ -82,7 +79,7 @@
         # managers can see all applied keyword, other users will only see validated
         # keywords or their own ones
         if self.req.user.is_in_group('managers'):
-            rset = entity.related(self.rtype, 'object')
+            rset = entity.related('applied_to', 'object')
         else:
             rset = self.cursor.execute('DISTINCT Any K,N WHERE K name N, K applied_to X, X eid %(x)s, '
                                        '(K owned_by U, U eid %(u)s) or (K in_state ST, ST name "keyword validated")',
@@ -99,13 +96,11 @@
 
 class AddKeywordVComponent(component.EntityVComponent):
     """the 'add keyword' component"""
-    __select__ = component.EntityVComponent.__select__ & rql_condition('X is ET, CL classifies ET')
+    id = 'addkeywords'
+    __select__ = component.EntityVComponent.__select__ & \
+                 relation_possible('applied_to', 'object', 'Keyword', action='add') & \
+                 rql_condition('X is ET, CL classifies ET')
 
-    id = 'addkeywords'
-    etype = 'Keyword'
-    rtype = 'applied_to'
-    target = 'subject'
-    require_permission = 'add'
     context = 'header'
     order = 153
     htmlclass = 'navigation'