20 @objectify_selector |
20 @objectify_selector |
21 def contextview_selector(cls, req, rset, row=None, col=None, view=None, |
21 def contextview_selector(cls, req, rset, row=None, col=None, view=None, |
22 **kwargs): |
22 **kwargs): |
23 if view and getattr(view, 'filter_box_context_info', lambda: None)(): |
23 if view and getattr(view, 'filter_box_context_info', lambda: None)(): |
24 return 1 |
24 return 1 |
25 return 0 |
25 return 0 |
26 |
26 |
27 |
27 |
28 class FilterBox(BoxTemplate): |
28 class FilterBox(BoxTemplate): |
29 """filter results of a query""" |
29 """filter results of a query""" |
30 id = 'filter_box' |
30 id = 'filter_box' |
40 def facetargs(self): |
40 def facetargs(self): |
41 """this method returns the list of extra arguments that should |
41 """this method returns the list of extra arguments that should |
42 be used by the facet |
42 be used by the facet |
43 """ |
43 """ |
44 return {} |
44 return {} |
45 |
45 |
46 def _get_context(self, view): |
46 def _get_context(self, view): |
47 context = getattr(view, 'filter_box_context_info', lambda: None)() |
47 context = getattr(view, 'filter_box_context_info', lambda: None)() |
48 if context: |
48 if context: |
49 rset, vid, divid, paginate = context |
49 rset, vid, divid, paginate = context |
50 else: |
50 else: |
51 rset = self.rset |
51 rset = self.rset |
52 vid, divid = None, 'pageContent' |
52 vid, divid = None, 'pageContent' |
53 paginate = view and view.need_navigation |
53 paginate = view and view.need_navigation |
54 return rset, vid, divid, paginate |
54 return rset, vid, divid, paginate |
55 |
55 |
56 def call(self, view=None): |
56 def call(self, view=None): |
57 req = self.req |
57 req = self.req |
58 req.add_js( ('cubicweb.ajax.js', 'cubicweb.formfilter.js') ) |
58 req.add_js( ('cubicweb.ajax.js', 'cubicweb.formfilter.js') ) |
59 req.add_css('cubicweb.facets.css') |
59 req.add_css('cubicweb.facets.css') |
60 if self.roundcorners: |
60 if self.roundcorners: |
107 |
107 |
108 def get_facets(self, rset, mainvar): |
108 def get_facets(self, rset, mainvar): |
109 return self.vreg.possible_vobjects('facets', self.req, rset, |
109 return self.vreg.possible_vobjects('facets', self.req, rset, |
110 context='facetbox', |
110 context='facetbox', |
111 filtered_variable=mainvar) |
111 filtered_variable=mainvar) |
112 |
112 |
113 # facets ###################################################################### |
113 # facets ###################################################################### |
114 |
114 |
115 class CreatedByFacet(RelationFacet): |
115 class CreatedByFacet(RelationFacet): |
116 id = 'created_by-facet' |
116 id = 'created_by-facet' |
117 rtype = 'created_by' |
117 rtype = 'created_by' |
142 def vocabulary(self): |
142 def vocabulary(self): |
143 """return vocabulary for this facet, eg a list of 2-uple (label, value) |
143 """return vocabulary for this facet, eg a list of 2-uple (label, value) |
144 """ |
144 """ |
145 etypes = self.rset.column_types(0) |
145 etypes = self.rset.column_types(0) |
146 return sorted((self.req._(etype), etype) for etype in etypes) |
146 return sorted((self.req._(etype), etype) for etype in etypes) |
147 |
147 |
148 def add_rql_restrictions(self): |
148 def add_rql_restrictions(self): |
149 """add restriction for this facet into the rql syntax tree""" |
149 """add restriction for this facet into the rql syntax tree""" |
150 value = self.req.form.get(self.id) |
150 value = self.req.form.get(self.id) |
151 if not value: |
151 if not value: |
152 return |
152 return |
160 role = 'subject' |
160 role = 'subject' |
161 order = 0 |
161 order = 0 |
162 @property |
162 @property |
163 def title(self): |
163 def title(self): |
164 return self.req._('has_text') |
164 return self.req._('has_text') |
165 |
165 |
166 def get_widget(self): |
166 def get_widget(self): |
167 """return the widget instance to use to display this facet |
167 """return the widget instance to use to display this facet |
168 |
168 |
169 default implentation expects a .vocabulary method on the facet and |
169 default implentation expects a .vocabulary method on the facet and |
170 return a combobox displaying this vocabulary |
170 return a combobox displaying this vocabulary |