62 from rql import parse, nodes, utils |
62 from rql import parse, nodes, utils |
63 |
63 |
64 from cubicweb import Unauthorized, typed_eid |
64 from cubicweb import Unauthorized, typed_eid |
65 from cubicweb.schema import display_name |
65 from cubicweb.schema import display_name |
66 from cubicweb.utils import make_uid |
66 from cubicweb.utils import make_uid |
67 from cubicweb.selectors import match_context_prop, partial_relation_possible |
67 from cubicweb.selectors import match_context_prop, partial_relation_possible, yes |
68 from cubicweb.appobject import AppObject |
68 from cubicweb.appobject import AppObject |
69 from cubicweb.web import RequestError, htmlwidgets |
69 from cubicweb.web import RequestError, htmlwidgets |
70 |
70 |
71 |
71 |
72 def rtype_facet_title(facet): |
72 def rtype_facet_title(facet): |
1013 won't work. This facet class is designed to be used for cases where |
1013 won't work. This facet class is designed to be used for cases where |
1014 :class:`RelationFacet` or :class:`RelationAttributeFacet` can't do the trick |
1014 :class:`RelationFacet` or :class:`RelationAttributeFacet` can't do the trick |
1015 (e.g when you want to filter on entities where are not directly linked to |
1015 (e.g when you want to filter on entities where are not directly linked to |
1016 the filtered entities). |
1016 the filtered entities). |
1017 """ |
1017 """ |
|
1018 __select__ = yes() # we don't want RelationFacet's selector |
1018 # must be specified |
1019 # must be specified |
1019 path = None |
1020 path = None |
1020 filter_variable = None |
1021 filter_variable = None |
1021 # may be specified |
1022 # may be specified |
1022 label_variable = None |
1023 label_variable = None |
1029 no_relation = False |
1030 no_relation = False |
1030 support_and = False |
1031 support_and = False |
1031 |
1032 |
1032 def __init__(self, *args, **kwargs): |
1033 def __init__(self, *args, **kwargs): |
1033 super(RQLPathFacet, self).__init__(*args, **kwargs) |
1034 super(RQLPathFacet, self).__init__(*args, **kwargs) |
|
1035 assert self.filter_variable != self.label_variable, \ |
|
1036 ('filter_variable and label_variable should be different. ' |
|
1037 'You may want to let label_variable undefined (ie None).') |
1034 assert self.path and isinstance(self.path, (list, tuple)), \ |
1038 assert self.path and isinstance(self.path, (list, tuple)), \ |
1035 'path should be a list of 3-uples, not %s' % self.path |
1039 'path should be a list of 3-uples, not %s' % self.path |
1036 for part in self.path: |
1040 for part in self.path: |
1037 if isinstance(part, basestring): |
1041 if isinstance(part, basestring): |
1038 part = part.split() |
1042 part = part.split() |
1039 assert len(part) == 3, \ |
1043 assert len(part) == 3, \ |
1040 'path should be a list of 3-uples, not %s' % part |
1044 'path should be a list of 3-uples, not %s' % part |
1042 def __repr__(self): |
1046 def __repr__(self): |
1043 return '<%s %s>' % (self.__class__.__name__, |
1047 return '<%s %s>' % (self.__class__.__name__, |
1044 ','.join(str(p) for p in self.path)) |
1048 ','.join(str(p) for p in self.path)) |
1045 |
1049 |
1046 def vocabulary(self): |
1050 def vocabulary(self): |
1047 """return vocabulary for this facet, eg a list of 2-uple (label, value) |
1051 """return vocabulary for this facet, eg a list of (label, value)""" |
1048 """ |
|
1049 select = self.select |
1052 select = self.select |
1050 select.save_state() |
1053 select.save_state() |
1051 if self.rql_sort: |
1054 if self.rql_sort: |
1052 sort = self.sortasc |
1055 sort = self.sortasc |
1053 else: |
1056 else: |