web/views/facets.py
changeset 7953 a37531c8a4a6
parent 7949 ce64860b3cdc
parent 7939 e107204d3b27
child 7956 db49658b2812
equal deleted inserted replaced
7951:b7c825b00f64 7953:a37531c8a4a6
    25 from cubicweb.appobject import objectify_selector
    25 from cubicweb.appobject import objectify_selector
    26 from cubicweb.selectors import (non_final_entity, multi_lines_rset,
    26 from cubicweb.selectors import (non_final_entity, multi_lines_rset,
    27                                 match_context_prop, yes, relation_possible)
    27                                 match_context_prop, yes, relation_possible)
    28 from cubicweb.utils import json_dumps
    28 from cubicweb.utils import json_dumps
    29 from cubicweb.web import component, facet as facetbase
    29 from cubicweb.web import component, facet as facetbase
       
    30 from cubicweb.rqlrewrite import add_types_restriction
    30 
    31 
    31 def facets(req, rset, context, mainvar=None):
    32 def facets(req, rset, context, mainvar=None):
    32     """return the base rql and a list of widgets for facets applying to the
    33     """return the base rql and a list of widgets for facets applying to the
    33     given rset/context (cached version of :func:`_facet`)
    34     given rset/context (cached version of :func:`_facet`)
    34 
    35 
    63     origqlst = rset.syntax_tree()
    64     origqlst = rset.syntax_tree()
    64     # union not yet supported
    65     # union not yet supported
    65     if len(origqlst.children) != 1:
    66     if len(origqlst.children) != 1:
    66         req.debug('facette disabled on union request %s', origqlst)
    67         req.debug('facette disabled on union request %s', origqlst)
    67         return None, ()
    68         return None, ()
       
    69 
       
    70     # Add type restriction to rql. This allow the get_type() method to return
       
    71     # useful value on variable extracted from a select statement.
       
    72     #
       
    73     # This is done on origqlst to ensure all rql related objects are properly
       
    74     # enriched when handled by a Facet:
       
    75     #    - the rset.syntax_tree() during selection
       
    76     #    - the select during selection
       
    77     #    - the select during filtering
       
    78 
       
    79     add_types_restriction(req.vreg.schema, origqlst.children[0])
    68     rqlst = origqlst.copy()
    80     rqlst = origqlst.copy()
    69     select = rqlst.children[0]
    81     select = rqlst.children[0]
    70     filtered_variable, baserql = facetbase.init_facets(rset, select, mainvar)
    82     filtered_variable, baserql = facetbase.init_facets(rset, select, mainvar)
    71     ### Selection
    83     ### Selection
    72     possible_facets = req.vreg['facets'].poss_visible_objects(
    84     possible_facets = req.vreg['facets'].poss_visible_objects(
   173         w(u'<fieldset>')
   185         w(u'<fieldset>')
   174         if mainvar:
   186         if mainvar:
   175             hiddens['mainvar'] = mainvar
   187             hiddens['mainvar'] = mainvar
   176         filter_hiddens(w, baserql, wdgs, **hiddens)
   188         filter_hiddens(w, baserql, wdgs, **hiddens)
   177         self.layout_widgets(w, self.sorted_widgets(wdgs))
   189         self.layout_widgets(w, self.sorted_widgets(wdgs))
       
   190 
       
   191         # <Enter> is supposed to submit the form only if there is a single
       
   192         # input:text field. However most browsers will submit the form
       
   193         # on <Enter> anyway if there is an input:submit field.
       
   194         #
       
   195         # see: http://www.w3.org/MarkUp/html-spec/html-spec_8.html#SEC8.2
       
   196         #
       
   197         # Firefox 7.0.1 does not submit form on <Enter> if there is more than a
       
   198         # input:text field and not input:submit but does it if there is an
       
   199         # input:submit.
       
   200         #
       
   201         # IE 6 or Firefox 2 behave the same way.
       
   202         w(u'<input type="submit" class="hidden" />')
       
   203         #
   178         w(u'</fieldset>\n')
   204         w(u'</fieldset>\n')
   179         w(u'</form>\n')
   205         w(u'</form>\n')
   180 
   206 
   181     def sorted_widgets(self, wdgs):
   207     def sorted_widgets(self, wdgs):
   182         """sort widgets: by default sort by widget height, then according to
   208         """sort widgets: by default sort by widget height, then according to