1174 |
1174 |
1175 @property |
1175 @property |
1176 def wdgclass(self): |
1176 def wdgclass(self): |
1177 return FacetRangeWidget |
1177 return FacetRangeWidget |
1178 |
1178 |
|
1179 def _range_rset(self): |
|
1180 select = self.select |
|
1181 select.save_state() |
|
1182 try: |
|
1183 filtered_variable = self.filtered_variable |
|
1184 cleanup_select(select, filtered_variable) |
|
1185 newvar = _add_rtype_relation(select, filtered_variable, self.rtype, self.role)[0] |
|
1186 minf = nodes.Function('MIN') |
|
1187 minf.append(nodes.VariableRef(newvar)) |
|
1188 select.add_selected(minf) |
|
1189 maxf = nodes.Function('MAX') |
|
1190 maxf.append(nodes.VariableRef(newvar)) |
|
1191 select.add_selected(maxf) |
|
1192 # add is restriction if necessary |
|
1193 if filtered_variable.stinfo['typerel'] is None: |
|
1194 etypes = frozenset(sol[filtered_variable.name] for sol in select.solutions) |
|
1195 select.add_type_restriction(filtered_variable, etypes) |
|
1196 try: |
|
1197 return self.rqlexec(select.as_string(), self.cw_rset.args) |
|
1198 except Exception: |
|
1199 self.exception('error while getting vocabulary for %s, rql: %s', |
|
1200 self, select.as_string()) |
|
1201 return () |
|
1202 finally: |
|
1203 select.recover() |
|
1204 |
|
1205 def vocabulary(self): |
|
1206 """return vocabulary for this facet, eg a list of 2-uple (label, value) |
|
1207 """ |
|
1208 rset = self._range_rset() |
|
1209 if rset: |
|
1210 minv, maxv = rset[0] |
|
1211 return [(unicode(minv), minv), (unicode(maxv), maxv)] |
|
1212 return [] |
|
1213 |
|
1214 def possible_values(self): |
|
1215 """Return a list of possible values (as string since it's used to |
|
1216 compare to a form value in javascript) for this facet. |
|
1217 """ |
|
1218 return [strval for strval, val in self.vocabulary()] |
|
1219 |
1179 def get_widget(self): |
1220 def get_widget(self): |
1180 """return the widget instance to use to display this facet""" |
1221 """return the widget instance to use to display this facet""" |
1181 values = set(value for _, value in self.vocabulary() if value is not None) |
1222 values = set(value for _, value in self.vocabulary() if value is not None) |
1182 # Rset with entities (the facet is selected) but without values |
1223 # Rset with entities (the facet is selected) but without values |
1183 if len(values) < 2: |
1224 if len(values) < 2: |