actions specific selector tls-sprint
authorsylvain.thenault@logilab.fr
Fri, 27 Mar 2009 12:25:24 +0100
branchtls-sprint
changeset 1178 8d9b705168d3
parent 1177 7074698c6522
child 1179 70825477c6ce
actions specific selector
selectors.py
web/views/actions.py
--- a/selectors.py	Fri Mar 27 12:24:47 2009 +0100
+++ b/selectors.py	Fri Mar 27 12:25:24 2009 +0100
@@ -655,26 +655,6 @@
         self.target_etype = getattr(cls, 'etype', None)
 
 
-class has_editable_relation(EntitySelector):
-    """accept if some relations for an entity found in the result set is
-    editable by the logged user.
-
-    See `EntitySelector` documentation for behaviour when row is not specified.
-    """
-        
-    def score_entity(self, entity):
-        # if user has no update right but it can modify some relation,
-        # display action anyway
-        for dummy in entity.srelations_by_category(('generic', 'metadata'),
-                                                   'add'):
-            return 1
-        for rschema, targetschemas, role in entity.relations_by_category(
-            ('primary', 'secondary'), 'add'):
-            if not rschema.is_final():
-                return 1
-        return 0
-
-
 class may_add_relation(EntitySelector):
     """accept if the relation can be added to an entity found in the result set
     by the logged user.
--- a/web/views/actions.py	Fri Mar 27 12:24:47 2009 +0100
+++ b/web/views/actions.py	Fri Mar 27 12:25:24 2009 +0100
@@ -7,17 +7,38 @@
 __docformat__ = "restructuredtext en"
 
 from cubicweb.vregistry import objectify_selector
-from cubicweb.selectors import (
+from cubicweb.selectors import (EntitySelector, 
     one_line_rset, two_lines_rset, one_etype_rset, relation_possible,
     non_final_entity,
     authenticated_user, match_user_groups, match_search_state,
-    has_editable_relation, has_permission, has_add_permission,
+    has_permission, has_add_permission,
     )
 from cubicweb.web.action import Action
 from cubicweb.web.views import linksearch_select_url, vid_from_rset
+from cubicweb.web.views.editforms import AutomaticEntityForm
 
 _ = unicode
 
+
+class has_editable_relation(EntitySelector):
+    """accept if some relations for an entity found in the result set is
+    editable by the logged user.
+
+    See `EntitySelector` documentation for behaviour when row is not specified.
+    """
+        
+    def score_entity(self, entity):
+        # if user has no update right but it can modify some relation,
+        # display action anyway
+        for dummy in AutomaticEntityForm.esrelations_by_category(
+            entity, 'generic', 'add'):
+            return 1
+        for rschema, targetschemas, role in AutomaticEntityForm.erelations_by_category(
+            entity, ('primary', 'secondary'), 'add'):
+            if not rschema.is_final():
+                return 1
+        return 0
+
 @objectify_selector
 def match_searched_etype(cls, req, rset, **kwargs):
     return req.match_search_state(rset)