web/facet.py
branchstable
changeset 7205 9220ae2cacf1
parent 7204 2b6d3c9455a7
child 7225 a4a115aab086
child 7233 614f23606091
equal deleted inserted replaced
7204:2b6d3c9455a7 7205:9220ae2cacf1
   938         # Rset with entities (the facet is selected) but without values
   938         # Rset with entities (the facet is selected) but without values
   939         if len(values) == 0:
   939         if len(values) == 0:
   940             return None
   940             return None
   941         return self.wdgclass(self, min(values), max(values))
   941         return self.wdgclass(self, min(values), max(values))
   942 
   942 
   943     def infvalue(self):
       
   944         return self._cw.form.get('%s_inf' % self.__regid__)
       
   945 
       
   946     def supvalue(self):
       
   947         return self._cw.form.get('%s_sup' % self.__regid__)
       
   948 
       
   949     def formatvalue(self, value):
   943     def formatvalue(self, value):
   950         """format `value` before in order to insert it in the RQL query"""
   944         """format `value` before in order to insert it in the RQL query"""
   951         return unicode(value)
   945         return unicode(value)
   952 
   946 
       
   947     def infvalue(self, min=False):
       
   948         if min:
       
   949             return self._cw.form.get('min_%s_inf' % self.__regid__)
       
   950         return self._cw.form.get('%s_inf' % self.__regid__)
       
   951 
       
   952     def supvalue(self, max=False):
       
   953         if max:
       
   954             return self._cw.form.get('max_%s_sup' % self.__regid__)
       
   955         return self._cw.form.get('%s_sup' % self.__regid__)
       
   956 
   953     def add_rql_restrictions(self):
   957     def add_rql_restrictions(self):
   954         infvalue = self.infvalue()
   958         infvalue = self.infvalue()
   955         if infvalue is None: # nothing sent
   959         supvalue = self.supvalue()
       
   960         if infvalue is None or supvalue is None: # nothing sent
   956             return
   961             return
   957         supvalue = self.supvalue()
   962         # when a value is equal to one of the limit, don't add the restriction,
   958         self.rqlst.add_constant_restriction(self.filtered_variable,
   963         # else we filter out NULL values implicitly
   959                                             self.rtype,
   964         if infvalue != self.infvalue(min=True):
   960                                             self.formatvalue(infvalue),
   965             self.rqlst.add_constant_restriction(self.filtered_variable,
   961                                             self.attrtype, '>=')
   966                                                 self.rtype,
   962         self.rqlst.add_constant_restriction(self.filtered_variable,
   967                                                 self.formatvalue(infvalue),
   963                                             self.rtype,
   968                                                 self.attrtype, '>=')
   964                                             self.formatvalue(supvalue),
   969         if supvalue != self.supvalue(max=True):
   965                                             self.attrtype, '<=')
   970             self.rqlst.add_constant_restriction(self.filtered_variable,
       
   971                                                 self.rtype,
       
   972                                                 self.formatvalue(supvalue),
       
   973                                                 self.attrtype, '<=')
   966 
   974 
   967 
   975 
   968 class DateRangeFacet(RangeFacet):
   976 class DateRangeFacet(RangeFacet):
   969     """This class works similarly as the :class:`RangeFacet` but for attribute
   977     """This class works similarly as the :class:`RangeFacet` but for attribute
   970     of date type.
   978     of date type.
  1136                % (sliderid, sliderid))
  1144                % (sliderid, sliderid))
  1137         self.w(u'<input type="hidden" name="%s_inf" value="%s" />'
  1145         self.w(u'<input type="hidden" name="%s_inf" value="%s" />'
  1138                % (facetid, self.minvalue))
  1146                % (facetid, self.minvalue))
  1139         self.w(u'<input type="hidden" name="%s_sup" value="%s" />'
  1147         self.w(u'<input type="hidden" name="%s_sup" value="%s" />'
  1140                % (facetid, self.maxvalue))
  1148                % (facetid, self.maxvalue))
       
  1149         self.w(u'<input type="hidden" name="min_%s_inf" value="%s" />'
       
  1150                % (facetid, self.minvalue))
       
  1151         self.w(u'<input type="hidden" name="max_%s_sup" value="%s" />'
       
  1152                % (facetid, self.maxvalue))
  1141         self.w(u'<div id="%s"></div>' % sliderid)
  1153         self.w(u'<div id="%s"></div>' % sliderid)
  1142         self.w(u'</div>\n')
  1154         self.w(u'</div>\n')
  1143 
  1155 
  1144 
  1156 
  1145 class DateFacetRangeWidget(FacetRangeWidget):
  1157 class DateFacetRangeWidget(FacetRangeWidget):