equal
deleted
inserted
replaced
449 |
449 |
450 def support_and(self): |
450 def support_and(self): |
451 return False |
451 return False |
452 |
452 |
453 |
453 |
|
454 def encode(obj, encoding): |
|
455 if isinstance(obj, unicode): |
|
456 return obj.encode(encoding) |
|
457 return unicode(obj).encode(encoding) |
|
458 |
454 class RelationFacet(VocabularyFacet): |
459 class RelationFacet(VocabularyFacet): |
455 """Base facet to filter some entities according to other entities to which |
460 """Base facet to filter some entities according to other entities to which |
456 they are related. Create concret facet by inheriting from this class an then |
461 they are related. Create concret facet by inheriting from this class an then |
457 configuring it by setting class attribute described below. |
462 configuring it by setting class attribute described below. |
458 |
463 |
603 self.role, select_target_entity=True) |
608 self.role, select_target_entity=True) |
604 else: |
609 else: |
605 insert_attr_select_relation( |
610 insert_attr_select_relation( |
606 rqlst, self.filtered_variable, self.rtype, self.role, self.target_attr, |
611 rqlst, self.filtered_variable, self.rtype, self.role, self.target_attr, |
607 select_target_entity=False) |
612 select_target_entity=False) |
608 values = [str(x) for x, in self.rqlexec(rqlst.as_string())] |
613 encoding = self._cw.encoding |
|
614 values = [encode(x, encoding) for x, in self.rqlexec(rqlst.as_string())] |
609 except: |
615 except: |
610 self.exception('while computing values for %s', self) |
616 self.exception('while computing values for %s', self) |
611 return [] |
617 return [] |
612 finally: |
618 finally: |
613 rqlst.recover() |
619 rqlst.recover() |
934 |
940 |
935 def get_widget(self): |
941 def get_widget(self): |
936 """return the widget instance to use to display this facet""" |
942 """return the widget instance to use to display this facet""" |
937 values = set(value for _, value in self.vocabulary() if value is not None) |
943 values = set(value for _, value in self.vocabulary() if value is not None) |
938 # Rset with entities (the facet is selected) but without values |
944 # Rset with entities (the facet is selected) but without values |
939 if len(values) == 0: |
945 if len(values) < 2: |
940 return None |
946 return None |
941 return self.wdgclass(self, min(values), max(values)) |
947 return self.wdgclass(self, min(values), max(values)) |
942 |
948 |
943 def formatvalue(self, value): |
949 def formatvalue(self, value): |
944 """format `value` before in order to insert it in the RQL query""" |
950 """format `value` before in order to insert it in the RQL query""" |
1123 self.minvalue = minvalue |
1129 self.minvalue = minvalue |
1124 self.maxvalue = maxvalue |
1130 self.maxvalue = maxvalue |
1125 |
1131 |
1126 def _render(self): |
1132 def _render(self): |
1127 facet = self.facet |
1133 facet = self.facet |
1128 facet._cw.add_js('ui.slider.js') |
1134 facet._cw.add_js('jquery.ui.js') |
1129 facet._cw.add_css('ui.all.css') |
1135 facet._cw.add_css('jquery.ui.css') |
1130 sliderid = make_uid('theslider') |
1136 sliderid = make_uid('theslider') |
1131 facetid = xml_escape(self.facet.__regid__) |
1137 facetid = xml_escape(self.facet.__regid__) |
1132 facet._cw.html_headers.add_onload(self.onload % { |
1138 facet._cw.html_headers.add_onload(self.onload % { |
1133 'sliderid': sliderid, |
1139 'sliderid': sliderid, |
1134 'facetid': facetid, |
1140 'facetid': facetid, |