rename abstract_* selectors into partial_* + add docstrings tls-sprint
authorAdrien Di Mascio <Adrien.DiMascio@logilab.fr>
Wed, 18 Feb 2009 23:11:01 +0100
branchtls-sprint
changeset 838 f2c56312b03a
parent 836 2ca048a43240
child 839 3a76e0a2a0b0
rename abstract_* selectors into partial_* + add docstrings
selectors.py
web/action.py
web/box.py
web/component.py
web/facet.py
web/views/tabs.py
--- a/selectors.py	Wed Feb 18 22:37:13 2009 +0100
+++ b/selectors.py	Wed Feb 18 23:11:01 2009 +0100
@@ -113,15 +113,15 @@
 
 
 # abstract selectors ##########################################################
-
-class AbstractSelectorMixIn(object):
-    """convenience mix-in for selectors that depends on class attributes
+class PartialSelectorMixIn(object):
+    """convenience mix-in for selectors that will look into the containing
+    class to find missing information.
+    
     cf. `cubicweb.web.action.LinkToEntityAction` for instance
     """
     def __call__(self, cls, *args, **kwargs):
-        self.concretize(cls)
-        return super(AbstractSelectorMixIn, self).__call__(cls, *args, **kwargs)
-
+        self.complete(cls)
+        return super(PartialSelectorMixIn, self).__call__(cls, *args, **kwargs)
 
 class EClassSelector(Selector):
     """abstract class for selectors working on the entity classes of the result
@@ -620,13 +620,29 @@
                 return 0
         return 1
 
+class partial_relation_possible(PartialSelectorMixIn, relation_possible):
+    """partial version of the relation_possible selector
 
-class abstract_relation_possible(AbstractSelectorMixIn, relation_possible):
+    The selector will look for class attributes to find its missing
+    information. The list of attributes required on the class
+    for this selector are:
+
+    - `rtype`: same as `rtype` parameter of the `relation_possible` selector
+    
+    - `role`: this attribute will be passed to the `cubicweb.role` function
+      to determine the role of class in the relation
+
+    - `etype` (optional): the entity type on the other side of the relation
+    
+    :param action: a relation schema action (one of 'read', 'add', 'delete')
+                   which must be granted to the logged user, else a 0 score will
+                   be returned
+    """
     def __init__(self, action='read', once_is_enough=False):
-        super(abstract_relation_possible, self).__init__(None, None, None,
-                                                         action, once_is_enough)
+        super(partial_relation_possible, self).__init__(None, None, None,
+                                                        action, once_is_enough)
 
-    def concretize(self, cls):
+    def complete(self, cls):
         self.rtype = cls.rtype
         self.role = role(cls)
         self.target_etype = getattr(cls, 'etype', None)
@@ -677,11 +693,26 @@
             return 0
         return 1
 
-class abstract_may_add_relation(AbstractSelectorMixIn, may_add_relation):
+class partial_may_add_relation(PartialSelectorMixIn, may_add_relation):
+    """partial version of the may_add_relation selector
+
+    The selector will look for class attributes to find its missing
+    information. The list of attributes required on the class
+    for this selector are:
+
+    - `rtype`: same as `rtype` parameter of the `relation_possible` selector
+    
+    - `role`: this attribute will be passed to the `cubicweb.role` function
+      to determine the role of class in the relation.
+    
+    :param action: a relation schema action (one of 'read', 'add', 'delete')
+                   which must be granted to the logged user, else a 0 score will
+                   be returned
+    """
     def __init__(self, once_is_enough=False):
-        super(abstract_may_add_relation, self).__init__(None, None, once_is_enough)
+        super(partial_may_add_relation, self).__init__(None, None, once_is_enough)
 
-    def concretize(self, cls):
+    def complete(self, cls):
         self.rtype = cls.rtype
         self.role = role(cls)
 
@@ -713,11 +744,28 @@
         return rset and 1 or 0
 
 
-class abstract_has_related_entities(AbstractSelectorMixIn, has_related_entities):
+class partial_has_related_entities(PartialSelectorMixIn, has_related_entities):
+    """partial version of the has_related_entities selector
+
+    The selector will look for class attributes to find its missing
+    information. The list of attributes required on the class
+    for this selector are:
+
+    - `rtype`: same as `rtype` parameter of the `relation_possible` selector
+    
+    - `role`: this attribute will be passed to the `cubicweb.role` function
+      to determine the role of class in the relation.
+
+    - `etype` (optional): the entity type on the other side of the relation
+    
+    :param action: a relation schema action (one of 'read', 'add', 'delete')
+                   which must be granted to the logged user, else a 0 score will
+                   be returned
+    """
     def __init__(self, once_is_enough=False):
-        super(abstract_has_related_entities, self).__init__(None, None,
-                                                            None, once_is_enough)
-    def concretize(self, cls):
+        super(partial_has_related_entities, self).__init__(None, None,
+                                                           None, once_is_enough)
+    def complete(self, cls):
         self.rtype = cls.rtype
         self.role = role(cls)
         self.target_etype = getattr(cls, 'etype', None)
--- a/web/action.py	Wed Feb 18 22:37:13 2009 +0100
+++ b/web/action.py	Wed Feb 18 23:11:01 2009 +0100
@@ -7,8 +7,8 @@
 __docformat__ = "restructuredtext en"
 
 from cubicweb import target
-from cubicweb.selectors import (abstract_relation_possible, match_search_state,
-                                one_line_rset, abstract_may_add_relation, yes,
+from cubicweb.selectors import (partial_relation_possible, match_search_state,
+                                one_line_rset, partial_may_add_relation, yes,
                                 accepts_compat, condition_compat, deprecate)
 from cubicweb.appobject import AppRsetObject
 from cubicweb.common.registerers import accepts_registerer
@@ -73,8 +73,8 @@
     action apply and if the logged user has access to it
     """
     __select__ = (match_search_state('normal') & one_line_rset()
-                  & abstract_relation_possible(action='add')
-                  & abstract_may_add_relation())
+                  & partial_relation_possible(action='add')
+                  & partial_may_add_relation())
     registered = accepts_compat(Action.registered)
     
     category = 'addrelated'
--- a/web/box.py	Wed Feb 18 22:37:13 2009 +0100
+++ b/web/box.py	Wed Feb 18 23:11:01 2009 +0100
@@ -11,7 +11,7 @@
 
 from cubicweb import Unauthorized, role as get_role
 from cubicweb.selectors import (one_line_rset,  primary_view,
-                                match_context_prop, abstract_has_related_entities,
+                                match_context_prop, partial_has_related_entities,
                                 accepts_compat, has_relation_compat,
                                 condition_compat, require_group_compat)
 from cubicweb.view import View, ReloadableMixIn
@@ -147,7 +147,7 @@
 
 
 class RelatedEntityBoxTemplate(EntityBoxTemplate):
-    __select__ = EntityBoxTemplate.__select__ & abstract_has_related_entities()
+    __select__ = EntityBoxTemplate.__select__ & partial_has_related_entities()
 
     def cell_call(self, row, col, **kwargs):
         entity = self.entity(row, col)
--- a/web/component.py	Wed Feb 18 22:37:13 2009 +0100
+++ b/web/component.py	Wed Feb 18 23:11:01 2009 +0100
@@ -14,7 +14,7 @@
 from cubicweb.view import View, Component
 from cubicweb.selectors import (
     paginated_rset, one_line_rset, primary_view, match_context_prop,
-    abstract_has_related_entities, abstract_relation_possible,
+    partial_has_related_entities, partial_relation_possible,
     condition_compat, accepts_compat, has_relation_compat)
 from cubicweb.common.registerers import accepts_registerer
 
@@ -143,7 +143,7 @@
 class RelatedObjectsVComponent(EntityVComponent):
     """a section to display some related entities"""
     vid = 'list'
-    __select__ = abstract_relation_possible() & abstract_has_related_entities()
+    __select__ = partial_relation_possible() & partial_has_related_entities()
     
     def rql(self):
         """override this method if you want to use a custom rql query"""
--- a/web/facet.py	Wed Feb 18 22:37:13 2009 +0100
+++ b/web/facet.py	Wed Feb 18 23:11:01 2009 +0100
@@ -19,7 +19,7 @@
 from rql import parse, nodes
 
 from cubicweb import Unauthorized, typed_eid
-from cubicweb.selectors import match_context_prop, abstract_relation_possible
+from cubicweb.selectors import match_context_prop, partial_relation_possible
 from cubicweb.appobject import AppRsetObject
 from cubicweb.common.registerers import priority_registerer
 from cubicweb.web.htmlwidgets import HTMLWidget
@@ -333,7 +333,7 @@
 
 
 class RelationFacet(VocabularyFacet):
-    __select__ = abstract_relation_possible() & match_context_prop()
+    __select__ = partial_relation_possible() & match_context_prop()
     # class attributes to configure the rel ation facet
     rtype = None
     role = 'subject' 
--- a/web/views/tabs.py	Wed Feb 18 22:37:13 2009 +0100
+++ b/web/views/tabs.py	Wed Feb 18 23:11:01 2009 +0100
@@ -11,7 +11,7 @@
 from logilab.mtconverter import html_escape
 
 from cubicweb import NoSelectableObject, role
-from cubicweb.selectors import abstract_has_related_entities
+from cubicweb.selectors import partial_has_related_entities
 from cubicweb.common.view import EntityView
 from cubicweb.common.utils import HTMLHead
 from cubicweb.common.uilib import rql_for_eid
@@ -143,7 +143,7 @@
     class ProjectScreenshotTab(DataDependantTab, ProjectScreenshotsView):
         id = 'screenshots_tab'
     """
-    __select__ = EntityView.__select__ & abstract_has_related_entities()
+    __select__ = EntityView.__select__ & partial_has_related_entities()
                                                           
     vid = 'list'