web/views/facets.py
changeset 8190 2a3c1b787688
parent 8128 0a927fe4541b
child 8551 6cf9e4da54a9
equal deleted inserted replaced
8189:2ee0ef069fa7 8190:2a3c1b787688
     1 # copyright 2003-2011 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
     1 # copyright 2003-2012 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
     2 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
     2 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
     3 #
     3 #
     4 # This file is part of CubicWeb.
     4 # This file is part of CubicWeb.
     5 #
     5 #
     6 # CubicWeb is free software: you can redistribute it and/or modify it under the
     6 # CubicWeb is free software: you can redistribute it and/or modify it under the
    22 
    22 
    23 from warnings import warn
    23 from warnings import warn
    24 
    24 
    25 from logilab.mtconverter import xml_escape
    25 from logilab.mtconverter import xml_escape
    26 from logilab.common.decorators import cachedproperty
    26 from logilab.common.decorators import cachedproperty
    27 
    27 from logilab.common.registry import objectify_predicate, yes
    28 from cubicweb.appobject import objectify_selector
    28 
    29 from cubicweb.selectors import (non_final_entity, multi_lines_rset,
    29 from cubicweb.predicates import (non_final_entity, multi_lines_rset,
    30                                 match_context_prop, yes, relation_possible)
    30                                  match_context_prop, relation_possible)
    31 from cubicweb.utils import json_dumps
    31 from cubicweb.utils import json_dumps
    32 from cubicweb.uilib import css_em_num_value
    32 from cubicweb.uilib import css_em_num_value
    33 from cubicweb.view import AnyRsetView
    33 from cubicweb.view import AnyRsetView
    34 from cubicweb.web import component, facet as facetbase
    34 from cubicweb.web import component, facet as facetbase
    35 from cubicweb.web.views.ajaxcontroller import ajaxfunc
    35 from cubicweb.web.views.ajaxcontroller import ajaxfunc
    80         context=context, filtered_variable=filtered_variable, **kwargs)
    80         context=context, filtered_variable=filtered_variable, **kwargs)
    81     wdgs = [(facet, facet.get_widget()) for facet in possible_facets]
    81     wdgs = [(facet, facet.get_widget()) for facet in possible_facets]
    82     return baserql, [wdg for facet, wdg in wdgs if wdg is not None]
    82     return baserql, [wdg for facet, wdg in wdgs if wdg is not None]
    83 
    83 
    84 
    84 
    85 @objectify_selector
    85 @objectify_predicate
    86 def contextview_selector(cls, req, rset=None, row=None, col=None, view=None,
    86 def contextview_selector(cls, req, rset=None, row=None, col=None, view=None,
    87                          **kwargs):
    87                          **kwargs):
    88     if view:
    88     if view:
    89         try:
    89         try:
    90             getcontext = getattr(view, 'filter_box_context_info')
    90             getcontext = getattr(view, 'filter_box_context_info')
    95             return 0
    95             return 0
    96         wdgs = facets(req, rset, cls.__regid__, view=view)[1]
    96         wdgs = facets(req, rset, cls.__regid__, view=view)[1]
    97         return len(wdgs)
    97         return len(wdgs)
    98     return 0
    98     return 0
    99 
    99 
   100 @objectify_selector
   100 @objectify_predicate
   101 def has_facets(cls, req, rset=None, **kwargs):
   101 def has_facets(cls, req, rset=None, **kwargs):
   102     if rset is None or rset.rowcount < 2:
   102     if rset is None or rset.rowcount < 2:
   103         return 0
   103         return 0
   104     wdgs = facets(req, rset, cls.__regid__, **kwargs)[1]
   104     wdgs = facets(req, rset, cls.__regid__, **kwargs)[1]
   105     return len(wdgs)
   105     return len(wdgs)