web/facet.py
changeset 10612 84468b90e9c1
parent 10597 44c52385d2d8
child 10663 54b8a1f249fb
equal deleted inserted replaced
10611:f4dec0cca9a1 10612:84468b90e9c1
    54 
    54 
    55 from functools import reduce
    55 from functools import reduce
    56 from warnings import warn
    56 from warnings import warn
    57 from copy import deepcopy
    57 from copy import deepcopy
    58 from datetime import datetime, timedelta
    58 from datetime import datetime, timedelta
       
    59 
       
    60 from six import string_types
    59 
    61 
    60 from logilab.mtconverter import xml_escape
    62 from logilab.mtconverter import xml_escape
    61 from logilab.common.graph import has_path
    63 from logilab.common.graph import has_path
    62 from logilab.common.decorators import cached, cachedproperty
    64 from logilab.common.decorators import cached, cachedproperty
    63 from logilab.common.date import datetime2ticks, ustrftime, ticks2datetime
    65 from logilab.common.date import datetime2ticks, ustrftime, ticks2datetime
   752 
   754 
   753     def value_restriction(self, restrvar, rel, value):
   755     def value_restriction(self, restrvar, rel, value):
   754         # XXX handle rel is None case in RQLPathFacet?
   756         # XXX handle rel is None case in RQLPathFacet?
   755         if self.restr_attr != 'eid':
   757         if self.restr_attr != 'eid':
   756             self.select.set_distinct(True)
   758             self.select.set_distinct(True)
   757         if isinstance(value, basestring):
   759         if isinstance(value, string_types):
   758             # only one value selected
   760             # only one value selected
   759             if value:
   761             if value:
   760                 self.select.add_constant_restriction(
   762                 self.select.add_constant_restriction(
   761                     restrvar, self.restr_attr, value,
   763                     restrvar, self.restr_attr, value,
   762                     self.restr_attr_type)
   764                     self.restr_attr_type)
  1069             ('filter_variable and label_variable should be different. '
  1071             ('filter_variable and label_variable should be different. '
  1070              'You may want to let label_variable undefined (ie None).')
  1072              'You may want to let label_variable undefined (ie None).')
  1071         assert self.path and isinstance(self.path, (list, tuple)), \
  1073         assert self.path and isinstance(self.path, (list, tuple)), \
  1072             'path should be a list of 3-uples, not %s' % self.path
  1074             'path should be a list of 3-uples, not %s' % self.path
  1073         for part in self.path:
  1075         for part in self.path:
  1074             if isinstance(part, basestring):
  1076             if isinstance(part, string_types):
  1075                 part = part.split()
  1077                 part = part.split()
  1076             assert len(part) == 3, \
  1078             assert len(part) == 3, \
  1077                    'path should be a list of 3-uples, not %s' % part
  1079                    'path should be a list of 3-uples, not %s' % part
  1078 
  1080 
  1079     def __repr__(self):
  1081     def __repr__(self):
  1145 
  1147 
  1146     def add_path_to_select(self, skiplabel=False, skipattrfilter=False):
  1148     def add_path_to_select(self, skiplabel=False, skipattrfilter=False):
  1147         varmap = {'X': self.filtered_variable}
  1149         varmap = {'X': self.filtered_variable}
  1148         actual_filter_variable = None
  1150         actual_filter_variable = None
  1149         for part in self.path:
  1151         for part in self.path:
  1150             if isinstance(part, basestring):
  1152             if isinstance(part, string_types):
  1151                 part = part.split()
  1153                 part = part.split()
  1152             subject, rtype, object = part
  1154             subject, rtype, object = part
  1153             if skiplabel and object == self.label_variable:
  1155             if skiplabel and object == self.label_variable:
  1154                 continue
  1156                 continue
  1155             if object == self.filter_variable:
  1157             if object == self.filter_variable:
  1388             return
  1390             return
  1389         varmap, restrvar = self.add_path_to_select(
  1391         varmap, restrvar = self.add_path_to_select(
  1390             skiplabel=True, skipattrfilter=True)
  1392             skiplabel=True, skipattrfilter=True)
  1391         restrel = None
  1393         restrel = None
  1392         for part in self.path:
  1394         for part in self.path:
  1393             if isinstance(part, basestring):
  1395             if isinstance(part, string_types):
  1394                 part = part.split()
  1396                 part = part.split()
  1395             subject, rtype, object = part
  1397             subject, rtype, object = part
  1396             if object == self.filter_variable:
  1398             if object == self.filter_variable:
  1397                 restrel = rtype
  1399                 restrel = rtype
  1398         assert restrel
  1400         assert restrel