web/views/facets.py
changeset 8026 98222e3bb804
parent 8000 9a73d5e762b0
parent 8025 11caeed5ae80
child 8036 140a093015f8
equal deleted inserted replaced
8024:ff8ea924b10f 8026:98222e3bb804
    27 from cubicweb.appobject import objectify_selector
    27 from cubicweb.appobject import objectify_selector
    28 from cubicweb.selectors import (non_final_entity, multi_lines_rset,
    28 from cubicweb.selectors import (non_final_entity, multi_lines_rset,
    29                                 match_context_prop, yes, relation_possible)
    29                                 match_context_prop, yes, relation_possible)
    30 from cubicweb.utils import json_dumps
    30 from cubicweb.utils import json_dumps
    31 from cubicweb.web import component, facet as facetbase
    31 from cubicweb.web import component, facet as facetbase
    32 from cubicweb.rqlrewrite import add_types_restriction
       
    33 
    32 
    34 def facets(req, rset, context, mainvar=None, **kwargs):
    33 def facets(req, rset, context, mainvar=None, **kwargs):
    35     """return the base rql and a list of widgets for facets applying to the
    34     """return the base rql and a list of widgets for facets applying to the
    36     given rset/context (cached version of :func:`_facet`)
    35     given rset/context (cached version of :func:`_facet`)
    37 
    36 
    66     origqlst = rset.syntax_tree()
    65     origqlst = rset.syntax_tree()
    67     # union not yet supported
    66     # union not yet supported
    68     if len(origqlst.children) != 1:
    67     if len(origqlst.children) != 1:
    69         req.debug('facette disabled on union request %s', origqlst)
    68         req.debug('facette disabled on union request %s', origqlst)
    70         return None, ()
    69         return None, ()
    71 
       
    72     # Add type restriction to rql. This allow the get_type() method to return
       
    73     # useful value on variable extracted from a select statement.
       
    74     #
       
    75     # This is done on origqlst to ensure all rql related objects are properly
       
    76     # enriched when handled by a Facet:
       
    77     #    - the rset.syntax_tree() during selection
       
    78     #    - the select during selection
       
    79     #    - the select during filtering
       
    80 
       
    81     add_types_restriction(req.vreg.schema, origqlst.children[0])
       
    82     rqlst = origqlst.copy()
    70     rqlst = origqlst.copy()
    83     select = rqlst.children[0]
    71     select = rqlst.children[0]
    84     filtered_variable, baserql = facetbase.init_facets(rset, select, mainvar)
    72     filtered_variable, baserql = facetbase.init_facets(rset, select, mainvar)
    85     ### Selection
    73     ### Selection
    86     possible_facets = req.vreg['facets'].poss_visible_objects(
    74     possible_facets = req.vreg['facets'].poss_visible_objects(