web/views/facets.py
author Pierre-Yves David <pierre-yves.david@logilab.fr>
Thu, 20 Jun 2013 16:19:27 +0200
changeset 9044 cfec5cc46008
parent 8551 6cf9e4da54a9
child 9379 b0b1148b6963
permissions -rw-r--r--
[testlib] gather all repository access logic in one place Refactoring of the repository access API in test is imminent. We plan to move from the "old" dbapi to the new repoapi. Gathering all impacted method in one place help to understand how all those method interact and help readability for both patch and resulting code. No code change is done at all in this changeset. The refactoring will code later.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
8190
2a3c1b787688 [vreg] move base registry implementation to logilab.common. Closes #1916014
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8128
diff changeset
     1
# copyright 2003-2012 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
5421
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5389
diff changeset
     2
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5389
diff changeset
     3
#
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5389
diff changeset
     4
# This file is part of CubicWeb.
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5389
diff changeset
     5
#
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5389
diff changeset
     6
# CubicWeb is free software: you can redistribute it and/or modify it under the
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5389
diff changeset
     7
# terms of the GNU Lesser General Public License as published by the Free
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5389
diff changeset
     8
# Software Foundation, either version 2.1 of the License, or (at your option)
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5389
diff changeset
     9
# any later version.
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5389
diff changeset
    10
#
5424
8ecbcbff9777 replace logilab-common by CubicWeb in disclaimer
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5421
diff changeset
    11
# CubicWeb is distributed in the hope that it will be useful, but WITHOUT
5421
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5389
diff changeset
    12
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5389
diff changeset
    13
# FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5389
diff changeset
    14
# details.
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5389
diff changeset
    15
#
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5389
diff changeset
    16
# You should have received a copy of the GNU Lesser General Public License along
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5389
diff changeset
    17
# with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
5940
0e3ae19b181a [uilib] refactor json_dumps code organization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
    18
"""the facets box and some basic facets"""
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    19
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    20
__docformat__ = "restructuredtext en"
6582
8eb7883b4223 [pylint] fix a bug of pylint detected errors and i18n pb (calling builtins._ instead of req._)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6463
diff changeset
    21
_ = unicode
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    22
7956
db49658b2812 add missing imports
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7953
diff changeset
    23
from warnings import warn
db49658b2812 add missing imports
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7953
diff changeset
    24
2312
af4d8f75c5db use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2283
diff changeset
    25
from logilab.mtconverter import xml_escape
8093
3efb83e4e8f3 [facets] do no stretch to the right when there are many facets; instead use a floating layout (closes #2093160)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8036
diff changeset
    26
from logilab.common.decorators import cachedproperty
8190
2a3c1b787688 [vreg] move base registry implementation to logilab.common. Closes #1916014
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8128
diff changeset
    27
from logilab.common.registry import objectify_predicate, yes
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    28
8551
6cf9e4da54a9 [facets] add link 'focus on selection' (closes #525277)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 8190
diff changeset
    29
from cubicweb import tags
8190
2a3c1b787688 [vreg] move base registry implementation to logilab.common. Closes #1916014
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8128
diff changeset
    30
from cubicweb.predicates import (non_final_entity, multi_lines_rset,
2a3c1b787688 [vreg] move base registry implementation to logilab.common. Closes #1916014
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8128
diff changeset
    31
                                 match_context_prop, relation_possible)
5940
0e3ae19b181a [uilib] refactor json_dumps code organization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
    32
from cubicweb.utils import json_dumps
8093
3efb83e4e8f3 [facets] do no stretch to the right when there are many facets; instead use a floating layout (closes #2093160)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8036
diff changeset
    33
from cubicweb.uilib import css_em_num_value
3efb83e4e8f3 [facets] do no stretch to the right when there are many facets; instead use a floating layout (closes #2093160)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8036
diff changeset
    34
from cubicweb.view import AnyRsetView
7600
75d208ab8444 [facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7402
diff changeset
    35
from cubicweb.web import component, facet as facetbase
8128
0a927fe4541b [controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 8104
diff changeset
    36
from cubicweb.web.views.ajaxcontroller import ajaxfunc
7600
75d208ab8444 [facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7402
diff changeset
    37
7996
8de58d2674d6 [facets] view should be propagated up to facet selection, so we can get different facets according to the view. Closes #2036527
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7956
diff changeset
    38
def facets(req, rset, context, mainvar=None, **kwargs):
7600
75d208ab8444 [facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7402
diff changeset
    39
    """return the base rql and a list of widgets for facets applying to the
7937
3453c5f0db21 [facets] FacetFilterMixIn: add documention for class and generate_form
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7849
diff changeset
    40
    given rset/context (cached version of :func:`_facet`)
3453c5f0db21 [facets] FacetFilterMixIn: add documention for class and generate_form
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7849
diff changeset
    41
3453c5f0db21 [facets] FacetFilterMixIn: add documention for class and generate_form
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7849
diff changeset
    42
    :param req: A :class:`~cubicweb.req.RequestSessionBase` object
3453c5f0db21 [facets] FacetFilterMixIn: add documention for class and generate_form
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7849
diff changeset
    43
    :param rset: A :class:`~cubicweb.rset.ResultSet`
3453c5f0db21 [facets] FacetFilterMixIn: add documention for class and generate_form
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7849
diff changeset
    44
    :param context: A string that match the ``__regid__`` of a ``FacetFilter``
3453c5f0db21 [facets] FacetFilterMixIn: add documention for class and generate_form
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7849
diff changeset
    45
    :param mainvar: A string that match a select var from the rset
7600
75d208ab8444 [facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7402
diff changeset
    46
    """
75d208ab8444 [facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7402
diff changeset
    47
    try:
75d208ab8444 [facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7402
diff changeset
    48
        cache = req.__rset_facets
75d208ab8444 [facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7402
diff changeset
    49
    except AttributeError:
75d208ab8444 [facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7402
diff changeset
    50
        cache = req.__rset_facets = {}
75d208ab8444 [facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7402
diff changeset
    51
    try:
7606
01b49ec8fe80 [facets] allow to specify on which rqlst's variable facets should be applied. Closes #1795915
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7605
diff changeset
    52
        return cache[(rset, context, mainvar)]
7600
75d208ab8444 [facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7402
diff changeset
    53
    except KeyError:
7996
8de58d2674d6 [facets] view should be propagated up to facet selection, so we can get different facets according to the view. Closes #2036527
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7956
diff changeset
    54
        facets = _facets(req, rset, context, mainvar, **kwargs)
7606
01b49ec8fe80 [facets] allow to specify on which rqlst's variable facets should be applied. Closes #1795915
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7605
diff changeset
    55
        cache[(rset, context, mainvar)] = facets
7600
75d208ab8444 [facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7402
diff changeset
    56
        return facets
75d208ab8444 [facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7402
diff changeset
    57
7996
8de58d2674d6 [facets] view should be propagated up to facet selection, so we can get different facets according to the view. Closes #2036527
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7956
diff changeset
    58
def _facets(req, rset, context, mainvar, **kwargs):
7600
75d208ab8444 [facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7402
diff changeset
    59
    """return the base rql and a list of widgets for facets applying to the
75d208ab8444 [facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7402
diff changeset
    60
    given rset/context
7937
3453c5f0db21 [facets] FacetFilterMixIn: add documention for class and generate_form
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7849
diff changeset
    61
3453c5f0db21 [facets] FacetFilterMixIn: add documention for class and generate_form
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7849
diff changeset
    62
    :param req: A :class:`~cubicweb.req.RequestSessionBase` object
3453c5f0db21 [facets] FacetFilterMixIn: add documention for class and generate_form
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7849
diff changeset
    63
    :param rset: A :class:`~cubicweb.rset.ResultSet`
3453c5f0db21 [facets] FacetFilterMixIn: add documention for class and generate_form
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7849
diff changeset
    64
    :param context: A string that match the ``__regid__`` of a ``FacetFilter``
3453c5f0db21 [facets] FacetFilterMixIn: add documention for class and generate_form
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7849
diff changeset
    65
    :param mainvar: A string that match a select var from the rset
7600
75d208ab8444 [facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7402
diff changeset
    66
    """
7937
3453c5f0db21 [facets] FacetFilterMixIn: add documention for class and generate_form
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7849
diff changeset
    67
    ### initialisation
7600
75d208ab8444 [facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7402
diff changeset
    68
    # XXX done by selectors, though maybe necessary when rset has been hijacked
75d208ab8444 [facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7402
diff changeset
    69
    # (e.g. contextview_selector matched)
7606
01b49ec8fe80 [facets] allow to specify on which rqlst's variable facets should be applied. Closes #1795915
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7605
diff changeset
    70
    origqlst = rset.syntax_tree()
7600
75d208ab8444 [facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7402
diff changeset
    71
    # union not yet supported
7606
01b49ec8fe80 [facets] allow to specify on which rqlst's variable facets should be applied. Closes #1795915
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7605
diff changeset
    72
    if len(origqlst.children) != 1:
7937
3453c5f0db21 [facets] FacetFilterMixIn: add documention for class and generate_form
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7849
diff changeset
    73
        req.debug('facette disabled on union request %s', origqlst)
7600
75d208ab8444 [facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7402
diff changeset
    74
        return None, ()
7606
01b49ec8fe80 [facets] allow to specify on which rqlst's variable facets should be applied. Closes #1795915
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7605
diff changeset
    75
    rqlst = origqlst.copy()
01b49ec8fe80 [facets] allow to specify on which rqlst's variable facets should be applied. Closes #1795915
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7605
diff changeset
    76
    select = rqlst.children[0]
01b49ec8fe80 [facets] allow to specify on which rqlst's variable facets should be applied. Closes #1795915
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7605
diff changeset
    77
    filtered_variable, baserql = facetbase.init_facets(rset, select, mainvar)
7937
3453c5f0db21 [facets] FacetFilterMixIn: add documention for class and generate_form
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7849
diff changeset
    78
    ### Selection
3453c5f0db21 [facets] FacetFilterMixIn: add documention for class and generate_form
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7849
diff changeset
    79
    possible_facets = req.vreg['facets'].poss_visible_objects(
7996
8de58d2674d6 [facets] view should be propagated up to facet selection, so we can get different facets according to the view. Closes #2036527
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7956
diff changeset
    80
        req, rset=rset, rqlst=origqlst, select=select,
8de58d2674d6 [facets] view should be propagated up to facet selection, so we can get different facets according to the view. Closes #2036527
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7956
diff changeset
    81
        context=context, filtered_variable=filtered_variable, **kwargs)
7937
3453c5f0db21 [facets] FacetFilterMixIn: add documention for class and generate_form
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7849
diff changeset
    82
    wdgs = [(facet, facet.get_widget()) for facet in possible_facets]
7606
01b49ec8fe80 [facets] allow to specify on which rqlst's variable facets should be applied. Closes #1795915
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7605
diff changeset
    83
    return baserql, [wdg for facet, wdg in wdgs if wdg is not None]
7600
75d208ab8444 [facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7402
diff changeset
    84
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    85
8190
2a3c1b787688 [vreg] move base registry implementation to logilab.common. Closes #1916014
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8128
diff changeset
    86
@objectify_predicate
2161
200481e7b156 prepare time where it won't be mandatory to give rset to select()
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
    87
def contextview_selector(cls, req, rset=None, row=None, col=None, view=None,
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    88
                         **kwargs):
7663
fb2501d29587 [facets] closes #1827464: facet box always appear
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7614
diff changeset
    89
    if view:
fb2501d29587 [facets] closes #1827464: facet box always appear
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7614
diff changeset
    90
        try:
fb2501d29587 [facets] closes #1827464: facet box always appear
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7614
diff changeset
    91
            getcontext = getattr(view, 'filter_box_context_info')
fb2501d29587 [facets] closes #1827464: facet box always appear
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7614
diff changeset
    92
        except AttributeError:
fb2501d29587 [facets] closes #1827464: facet box always appear
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7614
diff changeset
    93
            return 0
fb2501d29587 [facets] closes #1827464: facet box always appear
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7614
diff changeset
    94
        rset = getcontext()[0]
fb2501d29587 [facets] closes #1827464: facet box always appear
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7614
diff changeset
    95
        if rset is None or rset.rowcount < 2:
fb2501d29587 [facets] closes #1827464: facet box always appear
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7614
diff changeset
    96
            return 0
7996
8de58d2674d6 [facets] view should be propagated up to facet selection, so we can get different facets according to the view. Closes #2036527
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7956
diff changeset
    97
        wdgs = facets(req, rset, cls.__regid__, view=view)[1]
7663
fb2501d29587 [facets] closes #1827464: facet box always appear
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7614
diff changeset
    98
        return len(wdgs)
1802
d628defebc17 delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 1132
diff changeset
    99
    return 0
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   100
8190
2a3c1b787688 [vreg] move base registry implementation to logilab.common. Closes #1916014
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8128
diff changeset
   101
@objectify_predicate
7996
8de58d2674d6 [facets] view should be propagated up to facet selection, so we can get different facets according to the view. Closes #2036527
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7956
diff changeset
   102
def has_facets(cls, req, rset=None, **kwargs):
7663
fb2501d29587 [facets] closes #1827464: facet box always appear
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7614
diff changeset
   103
    if rset is None or rset.rowcount < 2:
7600
75d208ab8444 [facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7402
diff changeset
   104
        return 0
7996
8de58d2674d6 [facets] view should be propagated up to facet selection, so we can get different facets according to the view. Closes #2036527
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7956
diff changeset
   105
    wdgs = facets(req, rset, cls.__regid__, **kwargs)[1]
7663
fb2501d29587 [facets] closes #1827464: facet box always appear
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7614
diff changeset
   106
    return len(wdgs)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   107
7600
75d208ab8444 [facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7402
diff changeset
   108
75d208ab8444 [facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7402
diff changeset
   109
def filter_hiddens(w, baserql, wdgs, **kwargs):
75d208ab8444 [facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7402
diff changeset
   110
    kwargs['facets'] = ','.join(wdg.facet.__regid__ for wdg in wdgs)
75d208ab8444 [facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7402
diff changeset
   111
    kwargs['baserql'] = baserql
75d208ab8444 [facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7402
diff changeset
   112
    for key, val in kwargs.items():
75d208ab8444 [facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7402
diff changeset
   113
        w(u'<input type="hidden" name="%s" value="%s" />' % (
75d208ab8444 [facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7402
diff changeset
   114
            key, xml_escape(val)))
75d208ab8444 [facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7402
diff changeset
   115
75d208ab8444 [facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7402
diff changeset
   116
75d208ab8444 [facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7402
diff changeset
   117
class FacetFilterMixIn(object):
7937
3453c5f0db21 [facets] FacetFilterMixIn: add documention for class and generate_form
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7849
diff changeset
   118
    """Mixin Class to generate Facet Filter Form
3453c5f0db21 [facets] FacetFilterMixIn: add documention for class and generate_form
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7849
diff changeset
   119
7996
8de58d2674d6 [facets] view should be propagated up to facet selection, so we can get different facets according to the view. Closes #2036527
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7956
diff changeset
   120
    To generate the form, you need to explicitly call the following method:
7937
3453c5f0db21 [facets] FacetFilterMixIn: add documention for class and generate_form
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7849
diff changeset
   121
3453c5f0db21 [facets] FacetFilterMixIn: add documention for class and generate_form
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7849
diff changeset
   122
    .. automethod:: generate_form
3453c5f0db21 [facets] FacetFilterMixIn: add documention for class and generate_form
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7849
diff changeset
   123
7996
8de58d2674d6 [facets] view should be propagated up to facet selection, so we can get different facets according to the view. Closes #2036527
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7956
diff changeset
   124
    The most useful function to override is:
7937
3453c5f0db21 [facets] FacetFilterMixIn: add documention for class and generate_form
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7849
diff changeset
   125
3453c5f0db21 [facets] FacetFilterMixIn: add documention for class and generate_form
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7849
diff changeset
   126
    .. automethod:: layout_widgets
7996
8de58d2674d6 [facets] view should be propagated up to facet selection, so we can get different facets according to the view. Closes #2036527
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7956
diff changeset
   127
    """
7937
3453c5f0db21 [facets] FacetFilterMixIn: add documention for class and generate_form
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7849
diff changeset
   128
7600
75d208ab8444 [facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7402
diff changeset
   129
    needs_js = ['cubicweb.ajax.js', 'cubicweb.facets.js']
75d208ab8444 [facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7402
diff changeset
   130
    needs_css = ['cubicweb.facets.css']
75d208ab8444 [facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7402
diff changeset
   131
    roundcorners = True
75d208ab8444 [facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7402
diff changeset
   132
7996
8de58d2674d6 [facets] view should be propagated up to facet selection, so we can get different facets according to the view. Closes #2036527
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7956
diff changeset
   133
    def generate_form(self, w, rset, divid, vid, vidargs=None, mainvar=None,
8de58d2674d6 [facets] view should be propagated up to facet selection, so we can get different facets according to the view. Closes #2036527
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7956
diff changeset
   134
                      paginate=False, cssclass='', hiddens=None, **kwargs):
7937
3453c5f0db21 [facets] FacetFilterMixIn: add documention for class and generate_form
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7849
diff changeset
   135
        """display a form to filter some view's content
3453c5f0db21 [facets] FacetFilterMixIn: add documention for class and generate_form
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7849
diff changeset
   136
3453c5f0db21 [facets] FacetFilterMixIn: add documention for class and generate_form
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7849
diff changeset
   137
        :param w:        Write function
3453c5f0db21 [facets] FacetFilterMixIn: add documention for class and generate_form
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7849
diff changeset
   138
3453c5f0db21 [facets] FacetFilterMixIn: add documention for class and generate_form
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7849
diff changeset
   139
        :param rset:     ResultSet to be filtered
3453c5f0db21 [facets] FacetFilterMixIn: add documention for class and generate_form
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7849
diff changeset
   140
3453c5f0db21 [facets] FacetFilterMixIn: add documention for class and generate_form
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7849
diff changeset
   141
        :param divid:    Dom ID of the div where the rendering of the view is done.
3453c5f0db21 [facets] FacetFilterMixIn: add documention for class and generate_form
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7849
diff changeset
   142
        :type divid:     string
3453c5f0db21 [facets] FacetFilterMixIn: add documention for class and generate_form
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7849
diff changeset
   143
3453c5f0db21 [facets] FacetFilterMixIn: add documention for class and generate_form
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7849
diff changeset
   144
        :param vid:      ID of the view display in the div
3453c5f0db21 [facets] FacetFilterMixIn: add documention for class and generate_form
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7849
diff changeset
   145
        :type vid:       string
3453c5f0db21 [facets] FacetFilterMixIn: add documention for class and generate_form
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7849
diff changeset
   146
3453c5f0db21 [facets] FacetFilterMixIn: add documention for class and generate_form
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7849
diff changeset
   147
        :param paginate: Is the view paginated ?
3453c5f0db21 [facets] FacetFilterMixIn: add documention for class and generate_form
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7849
diff changeset
   148
        :type paginate:  boolean
3453c5f0db21 [facets] FacetFilterMixIn: add documention for class and generate_form
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7849
diff changeset
   149
3453c5f0db21 [facets] FacetFilterMixIn: add documention for class and generate_form
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7849
diff changeset
   150
        :param cssclass: Additional css classes to put on the form.
3453c5f0db21 [facets] FacetFilterMixIn: add documention for class and generate_form
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7849
diff changeset
   151
        :type cssclass:  string
3453c5f0db21 [facets] FacetFilterMixIn: add documention for class and generate_form
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7849
diff changeset
   152
3453c5f0db21 [facets] FacetFilterMixIn: add documention for class and generate_form
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7849
diff changeset
   153
        :param hiddens:  other hidden parametters to include in the forms.
3453c5f0db21 [facets] FacetFilterMixIn: add documention for class and generate_form
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7849
diff changeset
   154
        :type hiddens:   dict from extra keyword argument
3453c5f0db21 [facets] FacetFilterMixIn: add documention for class and generate_form
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7849
diff changeset
   155
        """
8000
9a73d5e762b0 [facets] fix context passing + a note for later
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 7996
diff changeset
   156
        # XXX Facet.context property hijacks an otherwise well-behaved
9a73d5e762b0 [facets] fix context passing + a note for later
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 7996
diff changeset
   157
        #     vocabulary with its own notions
9a73d5e762b0 [facets] fix context passing + a note for later
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 7996
diff changeset
   158
        #     Hence we whack here to avoid a clash
9a73d5e762b0 [facets] fix context passing + a note for later
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 7996
diff changeset
   159
        kwargs.pop('context', None)
7996
8de58d2674d6 [facets] view should be propagated up to facet selection, so we can get different facets according to the view. Closes #2036527
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7956
diff changeset
   160
        baserql, wdgs = facets(self._cw, rset, context=self.__regid__,
8de58d2674d6 [facets] view should be propagated up to facet selection, so we can get different facets according to the view. Closes #2036527
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7956
diff changeset
   161
                               mainvar=mainvar, **kwargs)
7663
fb2501d29587 [facets] closes #1827464: facet box always appear
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7614
diff changeset
   162
        assert wdgs
7600
75d208ab8444 [facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7402
diff changeset
   163
        self._cw.add_js(self.needs_js)
75d208ab8444 [facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7402
diff changeset
   164
        self._cw.add_css(self.needs_css)
75d208ab8444 [facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7402
diff changeset
   165
        self._cw.html_headers.define_var('facetLoadingMsg',
75d208ab8444 [facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7402
diff changeset
   166
                                         self._cw._('facet-loading-msg'))
75d208ab8444 [facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7402
diff changeset
   167
        if self.roundcorners:
75d208ab8444 [facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7402
diff changeset
   168
            self._cw.html_headers.add_onload(
75d208ab8444 [facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7402
diff changeset
   169
                'jQuery(".facet").corner("tl br 10px");')
7949
ce64860b3cdc [facets] on the way to vidargs removal
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7943
diff changeset
   170
        if vidargs is not None:
ce64860b3cdc [facets] on the way to vidargs removal
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7943
diff changeset
   171
            warn("[3.14] vidargs is deprecated. Maybe you're using some TableView?",
ce64860b3cdc [facets] on the way to vidargs removal
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7943
diff changeset
   172
                 DeprecationWarning, stacklevel=2)
ce64860b3cdc [facets] on the way to vidargs removal
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7943
diff changeset
   173
        else:
ce64860b3cdc [facets] on the way to vidargs removal
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7943
diff changeset
   174
            vidargs = {}
7600
75d208ab8444 [facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7402
diff changeset
   175
        vidargs = dict((k, v) for k, v in vidargs.iteritems() if v)
75d208ab8444 [facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7402
diff changeset
   176
        facetargs = xml_escape(json_dumps([divid, vid, paginate, vidargs]))
75d208ab8444 [facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7402
diff changeset
   177
        w(u'<form id="%sForm" class="%s" method="post" action="" '
75d208ab8444 [facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7402
diff changeset
   178
          'cubicweb:facetargs="%s" >' % (divid, cssclass, facetargs))
75d208ab8444 [facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7402
diff changeset
   179
        w(u'<fieldset>')
7996
8de58d2674d6 [facets] view should be propagated up to facet selection, so we can get different facets according to the view. Closes #2036527
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7956
diff changeset
   180
        if hiddens is None:
8de58d2674d6 [facets] view should be propagated up to facet selection, so we can get different facets according to the view. Closes #2036527
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7956
diff changeset
   181
            hiddens = {}
7606
01b49ec8fe80 [facets] allow to specify on which rqlst's variable facets should be applied. Closes #1795915
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7605
diff changeset
   182
        if mainvar:
01b49ec8fe80 [facets] allow to specify on which rqlst's variable facets should be applied. Closes #1795915
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7605
diff changeset
   183
            hiddens['mainvar'] = mainvar
7600
75d208ab8444 [facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7402
diff changeset
   184
        filter_hiddens(w, baserql, wdgs, **hiddens)
75d208ab8444 [facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7402
diff changeset
   185
        self.layout_widgets(w, self.sorted_widgets(wdgs))
7939
e107204d3b27 Add a hidden input:submit field in facets form (closes #1988784)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7936
diff changeset
   186
e107204d3b27 Add a hidden input:submit field in facets form (closes #1988784)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7936
diff changeset
   187
        # <Enter> is supposed to submit the form only if there is a single
e107204d3b27 Add a hidden input:submit field in facets form (closes #1988784)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7936
diff changeset
   188
        # input:text field. However most browsers will submit the form
e107204d3b27 Add a hidden input:submit field in facets form (closes #1988784)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7936
diff changeset
   189
        # on <Enter> anyway if there is an input:submit field.
e107204d3b27 Add a hidden input:submit field in facets form (closes #1988784)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7936
diff changeset
   190
        #
e107204d3b27 Add a hidden input:submit field in facets form (closes #1988784)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7936
diff changeset
   191
        # see: http://www.w3.org/MarkUp/html-spec/html-spec_8.html#SEC8.2
e107204d3b27 Add a hidden input:submit field in facets form (closes #1988784)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7936
diff changeset
   192
        #
e107204d3b27 Add a hidden input:submit field in facets form (closes #1988784)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7936
diff changeset
   193
        # Firefox 7.0.1 does not submit form on <Enter> if there is more than a
e107204d3b27 Add a hidden input:submit field in facets form (closes #1988784)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7936
diff changeset
   194
        # input:text field and not input:submit but does it if there is an
e107204d3b27 Add a hidden input:submit field in facets form (closes #1988784)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7936
diff changeset
   195
        # input:submit.
e107204d3b27 Add a hidden input:submit field in facets form (closes #1988784)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7936
diff changeset
   196
        #
e107204d3b27 Add a hidden input:submit field in facets form (closes #1988784)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7936
diff changeset
   197
        # IE 6 or Firefox 2 behave the same way.
e107204d3b27 Add a hidden input:submit field in facets form (closes #1988784)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7936
diff changeset
   198
        w(u'<input type="submit" class="hidden" />')
e107204d3b27 Add a hidden input:submit field in facets form (closes #1988784)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7936
diff changeset
   199
        #
7600
75d208ab8444 [facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7402
diff changeset
   200
        w(u'</fieldset>\n')
75d208ab8444 [facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7402
diff changeset
   201
        w(u'</form>\n')
75d208ab8444 [facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7402
diff changeset
   202
75d208ab8444 [facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7402
diff changeset
   203
    def sorted_widgets(self, wdgs):
75d208ab8444 [facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7402
diff changeset
   204
        """sort widgets: by default sort by widget height, then according to
75d208ab8444 [facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7402
diff changeset
   205
        widget.order (the original widgets order)
75d208ab8444 [facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7402
diff changeset
   206
        """
8093
3efb83e4e8f3 [facets] do no stretch to the right when there are many facets; instead use a floating layout (closes #2093160)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8036
diff changeset
   207
        return sorted(wdgs, key=lambda x: 99 * (not x.facet.start_unfolded) or x.height )
7600
75d208ab8444 [facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7402
diff changeset
   208
75d208ab8444 [facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7402
diff changeset
   209
    def layout_widgets(self, w, wdgs):
75d208ab8444 [facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7402
diff changeset
   210
        """layout widgets: by default simply render each of them
75d208ab8444 [facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7402
diff changeset
   211
        (i.e. succession of <div>)
75d208ab8444 [facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7402
diff changeset
   212
        """
75d208ab8444 [facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7402
diff changeset
   213
        for wdg in wdgs:
75d208ab8444 [facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7402
diff changeset
   214
            wdg.render(w=w)
75d208ab8444 [facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7402
diff changeset
   215
75d208ab8444 [facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7402
diff changeset
   216
75d208ab8444 [facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7402
diff changeset
   217
class FilterBox(FacetFilterMixIn, component.CtxComponent):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   218
    """filter results of a query"""
7600
75d208ab8444 [facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7402
diff changeset
   219
    __regid__ = 'facet.filterbox'
75d208ab8444 [facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7402
diff changeset
   220
    __select__ = ((non_final_entity() & has_facets())
75d208ab8444 [facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7402
diff changeset
   221
                  | contextview_selector()) # can't use has_facets because of
75d208ab8444 [facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7402
diff changeset
   222
                                            # contextview mecanism
6140
65a619eb31c4 [boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6040
diff changeset
   223
    context = 'left' # XXX doesn't support 'incontext', only 'left' or 'right'
6463
67b0ad068f5d i18n update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6427
diff changeset
   224
    title = _('facet.filters')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   225
    visible = True # functionality provided by the search box by default
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   226
    order = 1
2214
a6b42cf05407 [facets] slightly better attr names
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2213
diff changeset
   227
2325
363b66a15668 [cleaning] minor cleaning over last two checkins
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 2323
diff changeset
   228
    bk_linkbox_template = u'<div class="facetTitle">%s</div>'
2283
dc13ec07a70a cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2260
diff changeset
   229
7614
40f33b3d3ea6 [facetbox] put the facet box in a box
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 7610
diff changeset
   230
    def render_body(self, w, **kwargs):
7600
75d208ab8444 [facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7402
diff changeset
   231
        req = self._cw
75d208ab8444 [facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7402
diff changeset
   232
        rset, vid, divid, paginate = self._get_context()
7663
fb2501d29587 [facets] closes #1827464: facet box always appear
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7614
diff changeset
   233
        assert len(rset) > 1
7600
75d208ab8444 [facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7402
diff changeset
   234
        if vid is None:
75d208ab8444 [facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7402
diff changeset
   235
            vid = req.form.get('vid')
75d208ab8444 [facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7402
diff changeset
   236
        if self.bk_linkbox_template and req.vreg.schema['Bookmark'].has_perm(req, 'add'):
75d208ab8444 [facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7402
diff changeset
   237
            w(self.bookmark_link(rset))
8551
6cf9e4da54a9 [facets] add link 'focus on selection' (closes #525277)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 8190
diff changeset
   238
        w(self.focus_link(rset))
7600
75d208ab8444 [facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7402
diff changeset
   239
        hiddens = {}
75d208ab8444 [facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7402
diff changeset
   240
        for param in ('subvid', 'vtitle'):
75d208ab8444 [facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7402
diff changeset
   241
            if param in req.form:
75d208ab8444 [facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7402
diff changeset
   242
                hiddens[param] = req.form[param]
7996
8de58d2674d6 [facets] view should be propagated up to facet selection, so we can get different facets according to the view. Closes #2036527
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7956
diff changeset
   243
        self.generate_form(w, rset, divid, vid, paginate=paginate,
8de58d2674d6 [facets] view should be propagated up to facet selection, so we can get different facets according to the view. Closes #2036527
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7956
diff changeset
   244
                           hiddens=hiddens, **self.cw_extra_kwargs)
1802
d628defebc17 delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 1132
diff changeset
   245
6140
65a619eb31c4 [boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6040
diff changeset
   246
    def _get_context(self):
65a619eb31c4 [boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6040
diff changeset
   247
        view = self.cw_extra_kwargs.get('view')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   248
        context = getattr(view, 'filter_box_context_info', lambda: None)()
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   249
        if context:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   250
            rset, vid, divid, paginate = context
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   251
        else:
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   252
            rset = self.cw_rset
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   253
            vid, divid = None, 'pageContent'
4244
2c3de1953d00 rename need_navigation into paginable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4212
diff changeset
   254
            paginate = view and view.paginable
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   255
        return rset, vid, divid, paginate
1802
d628defebc17 delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 1132
diff changeset
   256
6040
9ae260b2d1c4 [facet] refactor bookmark this search link creation: check perm before calling the method, and use the new create url factory
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5940
diff changeset
   257
    def bookmark_link(self, rset):
9ae260b2d1c4 [facet] refactor bookmark this search link creation: check perm before calling the method, and use the new create url factory
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5940
diff changeset
   258
        req = self._cw
9ae260b2d1c4 [facet] refactor bookmark this search link creation: check perm before calling the method, and use the new create url factory
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5940
diff changeset
   259
        bk_path = u'rql=%s' % req.url_quote(rset.printable_rql())
9ae260b2d1c4 [facet] refactor bookmark this search link creation: check perm before calling the method, and use the new create url factory
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5940
diff changeset
   260
        if req.form.get('vid'):
9ae260b2d1c4 [facet] refactor bookmark this search link creation: check perm before calling the method, and use the new create url factory
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5940
diff changeset
   261
            bk_path += u'&vid=%s' % req.url_quote(req.form['vid'])
9ae260b2d1c4 [facet] refactor bookmark this search link creation: check perm before calling the method, and use the new create url factory
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5940
diff changeset
   262
        bk_path = u'view?' + bk_path
9ae260b2d1c4 [facet] refactor bookmark this search link creation: check perm before calling the method, and use the new create url factory
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5940
diff changeset
   263
        bk_title = req._('my custom search')
9ae260b2d1c4 [facet] refactor bookmark this search link creation: check perm before calling the method, and use the new create url factory
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5940
diff changeset
   264
        linkto = u'bookmarked_by:%s:subject' % req.user.eid
9ae260b2d1c4 [facet] refactor bookmark this search link creation: check perm before calling the method, and use the new create url factory
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5940
diff changeset
   265
        bkcls = req.vreg['etypes'].etype_class('Bookmark')
9ae260b2d1c4 [facet] refactor bookmark this search link creation: check perm before calling the method, and use the new create url factory
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5940
diff changeset
   266
        bk_add_url = bkcls.cw_create_url(req, path=bk_path, title=bk_title,
9ae260b2d1c4 [facet] refactor bookmark this search link creation: check perm before calling the method, and use the new create url factory
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5940
diff changeset
   267
                                         __linkto=linkto)
9ae260b2d1c4 [facet] refactor bookmark this search link creation: check perm before calling the method, and use the new create url factory
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5940
diff changeset
   268
        bk_base_url = bkcls.cw_create_url(req, title=bk_title, __linkto=linkto)
9ae260b2d1c4 [facet] refactor bookmark this search link creation: check perm before calling the method, and use the new create url factory
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5940
diff changeset
   269
        bk_link = u'<a cubicweb:target="%s" id="facetBkLink" href="%s">%s</a>' % (
9ae260b2d1c4 [facet] refactor bookmark this search link creation: check perm before calling the method, and use the new create url factory
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5940
diff changeset
   270
                xml_escape(bk_base_url), xml_escape(bk_add_url),
9ae260b2d1c4 [facet] refactor bookmark this search link creation: check perm before calling the method, and use the new create url factory
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5940
diff changeset
   271
                req._('bookmark this search'))
9ae260b2d1c4 [facet] refactor bookmark this search link creation: check perm before calling the method, and use the new create url factory
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5940
diff changeset
   272
        return self.bk_linkbox_template % bk_link
2260
080167dad19e split FilterBox call function
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 2215
diff changeset
   273
8551
6cf9e4da54a9 [facets] add link 'focus on selection' (closes #525277)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 8190
diff changeset
   274
    def focus_link(self, rset):
6cf9e4da54a9 [facets] add link 'focus on selection' (closes #525277)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 8190
diff changeset
   275
        return self.bk_linkbox_template % tags.a(self._cw._('focus on this selection'),
6cf9e4da54a9 [facets] add link 'focus on selection' (closes #525277)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 8190
diff changeset
   276
                                                 href=self._cw.url(), id='focusLink')
7600
75d208ab8444 [facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7402
diff changeset
   277
75d208ab8444 [facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7402
diff changeset
   278
class FilterTable(FacetFilterMixIn, AnyRsetView):
75d208ab8444 [facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7402
diff changeset
   279
    __regid__ = 'facet.filtertable'
7610
838a0c910bb5 [selectors, facet] make is_instance and other EClassSelector subclass gather entity classes from 'select' and 'filtered_variable' context information. Closes #1796732
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7606
diff changeset
   280
    __select__ = has_facets()
8093
3efb83e4e8f3 [facets] do no stretch to the right when there are many facets; instead use a floating layout (closes #2093160)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8036
diff changeset
   281
    average_perfacet_uncomputable_overhead = .3
7600
75d208ab8444 [facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7402
diff changeset
   282
7949
ce64860b3cdc [facets] on the way to vidargs removal
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7943
diff changeset
   283
    def call(self, vid, divid, vidargs=None, cssclass=''):
8036
140a093015f8 [facetable views] allow extra hiddens to be specified when selecting the facets form
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8026
diff changeset
   284
        hiddens = self.cw_extra_kwargs.setdefault('hiddens', {})
140a093015f8 [facetable views] allow extra hiddens to be specified when selecting the facets form
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8026
diff changeset
   285
        hiddens['fromformfilter'] = '1'
7949
ce64860b3cdc [facets] on the way to vidargs removal
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7943
diff changeset
   286
        self.generate_form(self.w, self.cw_rset, divid, vid, vidargs=vidargs,
8036
140a093015f8 [facetable views] allow extra hiddens to be specified when selecting the facets form
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8026
diff changeset
   287
                           cssclass=cssclass, **self.cw_extra_kwargs)
7600
75d208ab8444 [facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7402
diff changeset
   288
8093
3efb83e4e8f3 [facets] do no stretch to the right when there are many facets; instead use a floating layout (closes #2093160)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8036
diff changeset
   289
    @cachedproperty
3efb83e4e8f3 [facets] do no stretch to the right when there are many facets; instead use a floating layout (closes #2093160)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8036
diff changeset
   290
    def per_facet_height_overhead(self):
3efb83e4e8f3 [facets] do no stretch to the right when there are many facets; instead use a floating layout (closes #2093160)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8036
diff changeset
   291
        return (css_em_num_value(self._cw.vreg, 'facet_MarginBottom', .2) +
3efb83e4e8f3 [facets] do no stretch to the right when there are many facets; instead use a floating layout (closes #2093160)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8036
diff changeset
   292
                css_em_num_value(self._cw.vreg, 'facet_Padding', .2) +
3efb83e4e8f3 [facets] do no stretch to the right when there are many facets; instead use a floating layout (closes #2093160)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8036
diff changeset
   293
                self.average_perfacet_uncomputable_overhead)
7842
fa7e463cae9d [views/facets] simple horizontal layout when there are a few facets only (closes #1921709)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 7664
diff changeset
   294
7600
75d208ab8444 [facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7402
diff changeset
   295
    def layout_widgets(self, w, wdgs):
75d208ab8444 [facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7402
diff changeset
   296
        """layout widgets: put them in a table where each column should have
7943
ad0581296e2c [facets] try to get rid of arbitrary constants, be prettier and eat less space (closes #1988706)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 7937
diff changeset
   297
        sum(wdg.height) < wdg_stack_size.
7600
75d208ab8444 [facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7402
diff changeset
   298
        """
8093
3efb83e4e8f3 [facets] do no stretch to the right when there are many facets; instead use a floating layout (closes #2093160)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8036
diff changeset
   299
        w(u'<div class="filter">\n')
7600
75d208ab8444 [facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7402
diff changeset
   300
        widget_queue = []
75d208ab8444 [facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7402
diff changeset
   301
        queue_height = 0
8104
71d9fb78b772 [facets] forcing a fixed height to the group is a bad idea: the container will not properly overflow
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8093
diff changeset
   302
        wdg_stack_size = facetbase._DEFAULT_FACET_GROUP_HEIGHT
7600
75d208ab8444 [facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7402
diff changeset
   303
        for wdg in wdgs:
8093
3efb83e4e8f3 [facets] do no stretch to the right when there are many facets; instead use a floating layout (closes #2093160)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8036
diff changeset
   304
            height = wdg.height + self.per_facet_height_overhead
7849
7937cf60f2ce [facets] fix height computation (incorporates and/or element if present, use css value to compute likely maximum height, kill wdg_stack_size) (closes #1954077)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 7842
diff changeset
   305
            if queue_height + height <= wdg_stack_size:
7600
75d208ab8444 [facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7402
diff changeset
   306
                widget_queue.append(wdg)
75d208ab8444 [facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7402
diff changeset
   307
                queue_height += height
75d208ab8444 [facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7402
diff changeset
   308
                continue
8093
3efb83e4e8f3 [facets] do no stretch to the right when there are many facets; instead use a floating layout (closes #2093160)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8036
diff changeset
   309
            w(u'<div class="facetGroup">')
7600
75d208ab8444 [facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7402
diff changeset
   310
            for queued in widget_queue:
75d208ab8444 [facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7402
diff changeset
   311
                queued.render(w=w)
8093
3efb83e4e8f3 [facets] do no stretch to the right when there are many facets; instead use a floating layout (closes #2093160)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8036
diff changeset
   312
            w(u'</div>')
7600
75d208ab8444 [facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7402
diff changeset
   313
            widget_queue = [wdg]
75d208ab8444 [facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7402
diff changeset
   314
            queue_height = height
75d208ab8444 [facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7402
diff changeset
   315
        if widget_queue:
8093
3efb83e4e8f3 [facets] do no stretch to the right when there are many facets; instead use a floating layout (closes #2093160)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8036
diff changeset
   316
            w(u'<div class="facetGroup">')
7600
75d208ab8444 [facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7402
diff changeset
   317
            for queued in widget_queue:
75d208ab8444 [facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7402
diff changeset
   318
                queued.render(w=w)
8093
3efb83e4e8f3 [facets] do no stretch to the right when there are many facets; instead use a floating layout (closes #2093160)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8036
diff changeset
   319
            w(u'</div>')
3efb83e4e8f3 [facets] do no stretch to the right when there are many facets; instead use a floating layout (closes #2093160)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8036
diff changeset
   320
        w(u'</div>\n')
7600
75d208ab8444 [facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7402
diff changeset
   321
8128
0a927fe4541b [controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 8104
diff changeset
   322
# python-ajax remote functions used by facet widgets #########################
0a927fe4541b [controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 8104
diff changeset
   323
0a927fe4541b [controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 8104
diff changeset
   324
@ajaxfunc(output_type='json')
0a927fe4541b [controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 8104
diff changeset
   325
def filter_build_rql(self, names, values):
0a927fe4541b [controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 8104
diff changeset
   326
    form = self._rebuild_posted_form(names, values)
0a927fe4541b [controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 8104
diff changeset
   327
    self._cw.form = form
0a927fe4541b [controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 8104
diff changeset
   328
    builder = facetbase.FilterRQLBuilder(self._cw)
0a927fe4541b [controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 8104
diff changeset
   329
    return builder.build_rql()
0a927fe4541b [controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 8104
diff changeset
   330
0a927fe4541b [controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 8104
diff changeset
   331
@ajaxfunc(output_type='json')
0a927fe4541b [controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 8104
diff changeset
   332
def filter_select_content(self, facetids, rql, mainvar):
0a927fe4541b [controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 8104
diff changeset
   333
    # Union unsupported yet
0a927fe4541b [controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 8104
diff changeset
   334
    select = self._cw.vreg.parse(self._cw, rql).children[0]
0a927fe4541b [controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 8104
diff changeset
   335
    filtered_variable = facetbase.get_filtered_variable(select, mainvar)
0a927fe4541b [controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 8104
diff changeset
   336
    facetbase.prepare_select(select, filtered_variable)
0a927fe4541b [controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 8104
diff changeset
   337
    update_map = {}
0a927fe4541b [controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 8104
diff changeset
   338
    for fid in facetids:
0a927fe4541b [controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 8104
diff changeset
   339
        fobj = facetbase.get_facet(self._cw, fid, select, filtered_variable)
0a927fe4541b [controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 8104
diff changeset
   340
        update_map[fid] = fobj.possible_values()
0a927fe4541b [controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 8104
diff changeset
   341
    return update_map
0a927fe4541b [controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 8104
diff changeset
   342
0a927fe4541b [controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 8104
diff changeset
   343
1802
d628defebc17 delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 1132
diff changeset
   344
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   345
# facets ######################################################################
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   346
7600
75d208ab8444 [facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7402
diff changeset
   347
class CWSourceFacet(facetbase.RelationFacet):
6427
c8a5ac2d1eaa [schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6141
diff changeset
   348
    __regid__ = 'cw_source-facet'
c8a5ac2d1eaa [schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6141
diff changeset
   349
    rtype = 'cw_source'
c8a5ac2d1eaa [schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6141
diff changeset
   350
    target_attr = 'name'
c8a5ac2d1eaa [schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6141
diff changeset
   351
7600
75d208ab8444 [facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7402
diff changeset
   352
class CreatedByFacet(facetbase.RelationFacet):
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3023
diff changeset
   353
    __regid__ = 'created_by-facet'
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   354
    rtype = 'created_by'
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   355
    target_attr = 'login'
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   356
7600
75d208ab8444 [facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7402
diff changeset
   357
class InGroupFacet(facetbase.RelationFacet):
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3023
diff changeset
   358
    __regid__ = 'in_group-facet'
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   359
    rtype = 'in_group'
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   360
    target_attr = 'name'
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   361
7600
75d208ab8444 [facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7402
diff changeset
   362
class InStateFacet(facetbase.RelationAttributeFacet):
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3023
diff changeset
   363
    __regid__ = 'in_state-facet'
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   364
    rtype = 'in_state'
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   365
    target_attr = 'name'
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   366
7605
48abeac162fd [facets] refactor / cleanup facet api: more consistent variable naming and easier to reuse function. Closes #1796804
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7600
diff changeset
   367
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   368
# inherit from RelationFacet to benefit from its possible_values implementation
7600
75d208ab8444 [facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7402
diff changeset
   369
class ETypeFacet(facetbase.RelationFacet):
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3023
diff changeset
   370
    __regid__ = 'etype-facet'
742
99115e029dca replaced most of __selectors__ assignments with __select__
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 692
diff changeset
   371
    __select__ = yes()
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   372
    order = 1
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   373
    rtype = 'is'
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   374
    target_attr = 'name'
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   375
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   376
    @property
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   377
    def title(self):
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   378
        return self._cw._('entity type')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   379
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   380
    def vocabulary(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   381
        """return vocabulary for this facet, eg a list of 2-uple (label, value)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   382
        """
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   383
        etypes = self.cw_rset.column_types(0)
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   384
        return sorted((self._cw._(etype), etype) for etype in etypes)
1802
d628defebc17 delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 1132
diff changeset
   385
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   386
    def add_rql_restrictions(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   387
        """add restriction for this facet into the rql syntax tree"""
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   388
        value = self._cw.form.get(self.__regid__)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   389
        if not value:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   390
            return
7605
48abeac162fd [facets] refactor / cleanup facet api: more consistent variable naming and easier to reuse function. Closes #1796804
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7600
diff changeset
   391
        self.select.add_type_restriction(self.filtered_variable, value)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   392
2337
6620e5abcd99 select right possible_values for ETypeFacet
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 2323
diff changeset
   393
    def possible_values(self):
6620e5abcd99 select right possible_values for ETypeFacet
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 2323
diff changeset
   394
        """return a list of possible values (as string since it's used to
6620e5abcd99 select right possible_values for ETypeFacet
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 2323
diff changeset
   395
        compare to a form value in javascript) for this facet
6620e5abcd99 select right possible_values for ETypeFacet
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 2323
diff changeset
   396
        """
7605
48abeac162fd [facets] refactor / cleanup facet api: more consistent variable naming and easier to reuse function. Closes #1796804
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7600
diff changeset
   397
        select = self.select
48abeac162fd [facets] refactor / cleanup facet api: more consistent variable naming and easier to reuse function. Closes #1796804
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7600
diff changeset
   398
        select.save_state()
2337
6620e5abcd99 select right possible_values for ETypeFacet
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 2323
diff changeset
   399
        try:
7605
48abeac162fd [facets] refactor / cleanup facet api: more consistent variable naming and easier to reuse function. Closes #1796804
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7600
diff changeset
   400
            facetbase.cleanup_select(select, self.filtered_variable)
48abeac162fd [facets] refactor / cleanup facet api: more consistent variable naming and easier to reuse function. Closes #1796804
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7600
diff changeset
   401
            etype_var = facetbase.prepare_vocabulary_select(
48abeac162fd [facets] refactor / cleanup facet api: more consistent variable naming and easier to reuse function. Closes #1796804
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7600
diff changeset
   402
                select, self.filtered_variable, self.rtype, self.role)
48abeac162fd [facets] refactor / cleanup facet api: more consistent variable naming and easier to reuse function. Closes #1796804
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7600
diff changeset
   403
            attrvar = select.make_variable()
48abeac162fd [facets] refactor / cleanup facet api: more consistent variable naming and easier to reuse function. Closes #1796804
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7600
diff changeset
   404
            select.add_selected(attrvar)
48abeac162fd [facets] refactor / cleanup facet api: more consistent variable naming and easier to reuse function. Closes #1796804
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7600
diff changeset
   405
            select.add_relation(etype_var, 'name', attrvar)
48abeac162fd [facets] refactor / cleanup facet api: more consistent variable naming and easier to reuse function. Closes #1796804
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7600
diff changeset
   406
            return [etype for _, etype in self.rqlexec(select.as_string())]
2337
6620e5abcd99 select right possible_values for ETypeFacet
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 2323
diff changeset
   407
        finally:
7605
48abeac162fd [facets] refactor / cleanup facet api: more consistent variable naming and easier to reuse function. Closes #1796804
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7600
diff changeset
   408
            select.recover()
48abeac162fd [facets] refactor / cleanup facet api: more consistent variable naming and easier to reuse function. Closes #1796804
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7600
diff changeset
   409
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   410
7600
75d208ab8444 [facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7402
diff changeset
   411
class HasTextFacet(facetbase.AbstractFacet):
742
99115e029dca replaced most of __selectors__ assignments with __select__
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 692
diff changeset
   412
    __select__ = relation_possible('has_text', 'subject') & match_context_prop()
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3023
diff changeset
   413
    __regid__ = 'has_text-facet'
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   414
    rtype = 'has_text'
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   415
    role = 'subject'
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   416
    order = 0
7402
826e5663a686 [facets/table] vertically group facets by two when possible in order to have a more compact horizontal layout in table filter form
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 7300
diff changeset
   417
826e5663a686 [facets/table] vertically group facets by two when possible in order to have a more compact horizontal layout in table filter form
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 7300
diff changeset
   418
    @property
826e5663a686 [facets/table] vertically group facets by two when possible in order to have a more compact horizontal layout in table filter form
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 7300
diff changeset
   419
    def wdgclass(self):
7600
75d208ab8444 [facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7402
diff changeset
   420
        return facetbase.FacetStringWidget
7402
826e5663a686 [facets/table] vertically group facets by two when possible in order to have a more compact horizontal layout in table filter form
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 7300
diff changeset
   421
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   422
    @property
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   423
    def title(self):
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   424
        return self._cw._('has_text')
1802
d628defebc17 delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 1132
diff changeset
   425
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   426
    def get_widget(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   427
        """return the widget instance to use to display this facet
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   428
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   429
        default implentation expects a .vocabulary method on the facet and
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   430
        return a combobox displaying this vocabulary
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   431
        """
7402
826e5663a686 [facets/table] vertically group facets by two when possible in order to have a more compact horizontal layout in table filter form
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 7300
diff changeset
   432
        return self.wdgclass(self)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   433
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   434
    def add_rql_restrictions(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   435
        """add restriction for this facet into the rql syntax tree"""
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   436
        value = self._cw.form.get(self.__regid__)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   437
        if not value:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   438
            return
7605
48abeac162fd [facets] refactor / cleanup facet api: more consistent variable naming and easier to reuse function. Closes #1796804
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7600
diff changeset
   439
        self.select.add_constant_restriction(self.filtered_variable, 'has_text', value, 'String')