[facet] more api cleanup: support_and should be a property, so it's easier to deactivate.
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Fri, 01 Jul 2011 16:20:45 +0200
changeset 7608 47311917a548
parent 7607 d332ecfc224a
child 7609 fbefd1b9e587
[facet] more api cleanup: support_and should be a property, so it's easier to deactivate.
web/facet.py
--- a/web/facet.py	Fri Jul 01 15:26:45 2011 +0200
+++ b/web/facet.py	Fri Jul 01 16:20:45 2011 +0200
@@ -457,6 +457,7 @@
     .. automethod:: cubicweb.web.facet.VocabularyFacet.possible_values
     """
     needs_update = True
+    support_and = False
 
     @property
     def wdgclass(self):
@@ -491,8 +492,6 @@
         """
         raise NotImplementedError
 
-    def support_and(self):
-        return False
 
 
 class RelationFacet(VocabularyFacet):
@@ -694,11 +693,20 @@
                 values = list(reversed(values))
         return values
 
+    @property
     def support_and(self):
         return self._search_card('+*')
 
     # internal utilities #######################################################
 
+    def _support_and_compat(self):
+        support = self.support_and
+        if callable(support):
+            warn('[3.13] %s.support_and is now a property' % self.__class__,
+                 DeprecationWarning)
+            support = support()
+        return support
+
     def value_restriction(self, restrvar, rel, value):
         if isinstance(value, basestring):
             # only one value selected
@@ -708,7 +716,7 @@
                 rel.parent.replace(rel, nodes.Not(rel))
         elif self.operator == 'OR':
             # set_distinct only if rtype cardinality is > 1
-            if self.support_and():
+            if self._support_and_compat():
                 self.select.set_distinct(True)
             # multiple ORed values: using IN is fine
             if '' in value:
@@ -906,6 +914,7 @@
                       ('> 275', '275'), ('> 300', '300')]
     """
 
+    support_and = False
     _select_target_entity = True
 
     @property
@@ -940,9 +949,6 @@
         # *list* (see rqlexec implementation)
         return rset and self.rset_vocabulary(rset)
 
-    def support_and(self):
-        return False
-
     def add_rql_restrictions(self):
         """add restriction for this facet into the rql syntax tree"""
         value = self._cw.form.get(self.__regid__)
@@ -1081,9 +1087,7 @@
     role = 'subject' # role of filtered entity in the relation
 
     title = property(rtype_facet_title)
-
-    def support_and(self):
-        return False
+    support_and = False
 
     def get_widget(self):
         return CheckBoxFacetWidget(self._cw, self,
@@ -1124,7 +1128,7 @@
         w(u'<div id="%s" class="facet">\n' % facetid)
         w(u'<div class="facetTitle" cubicweb:facetName="%s">%s</div>\n' %
           (xml_escape(facetid), title))
-        if self.facet.support_and():
+        if self.facet._support_and_compat():
             _ = self.facet._cw._
             w(u'''<select name="%s" class="radio facetOperator" title="%s">
   <option value="OR">%s</option>