author | Nicolas Chauvat <nicolas.chauvat@logilab.fr> |
Mon, 09 Aug 2010 16:35:49 +0200 | |
branch | stable |
changeset 6079 | bd7e3042791e |
parent 5394 | 105011657405 |
child 6120 | c000e41316ec |
permissions | -rw-r--r-- |
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
1 |
The facets system |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
2 |
----------------- |
5286
43d7044f8d0b
[doc/book] complete the facet section
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
4751
diff
changeset
|
3 |
|
5394
105011657405
[doc/book] move devweb up from development, turn development into devrepo (much better structure)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5286
diff
changeset
|
4 |
Facets allow to restrict searches according to some criteria. CubicWeb |
105011657405
[doc/book] move devweb up from development, turn development into devrepo (much better structure)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5286
diff
changeset
|
5 |
has a builtin `facet`_ system to define restrictions `filters`_ really |
105011657405
[doc/book] move devweb up from development, turn development into devrepo (much better structure)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5286
diff
changeset
|
6 |
as easily as possible. A few base classes for facets are provided in |
105011657405
[doc/book] move devweb up from development, turn development into devrepo (much better structure)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5286
diff
changeset
|
7 |
``cubicweb.web.facet.py``. All classes inherits from the base class |
105011657405
[doc/book] move devweb up from development, turn development into devrepo (much better structure)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5286
diff
changeset
|
8 |
``AbstractFacet``. |
5286
43d7044f8d0b
[doc/book] complete the facet section
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
4751
diff
changeset
|
9 |
|
43d7044f8d0b
[doc/book] complete the facet section
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
4751
diff
changeset
|
10 |
Here is an overview of the facets rendering pick from the `tracker` cube: |
43d7044f8d0b
[doc/book] complete the facet section
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
4751
diff
changeset
|
11 |
|
5394
105011657405
[doc/book] move devweb up from development, turn development into devrepo (much better structure)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5286
diff
changeset
|
12 |
.. image:: ../images/facet_overview.png |
5286
43d7044f8d0b
[doc/book] complete the facet section
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
4751
diff
changeset
|
13 |
|
43d7044f8d0b
[doc/book] complete the facet section
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
4751
diff
changeset
|
14 |
Facets will appear on each page presenting more than one entity. |
43d7044f8d0b
[doc/book] complete the facet section
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
4751
diff
changeset
|
15 |
|
3991
a0aa9789c6bc
Pasting blog about facet in the facet section of the doc book.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
1714
diff
changeset
|
16 |
|
a0aa9789c6bc
Pasting blog about facet in the facet section of the doc book.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
1714
diff
changeset
|
17 |
|
5286
43d7044f8d0b
[doc/book] complete the facet section
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
4751
diff
changeset
|
18 |
VocabularyFacet |
43d7044f8d0b
[doc/book] complete the facet section
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
4751
diff
changeset
|
19 |
~~~~~~~~~~~~~~~~ |
43d7044f8d0b
[doc/book] complete the facet section
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
4751
diff
changeset
|
20 |
The ``VocabularyFacet`` inherits from the ``AbstractFacet``. |
43d7044f8d0b
[doc/book] complete the facet section
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
4751
diff
changeset
|
21 |
A class which inherits from VocabularyFacets must redefine these methods: |
43d7044f8d0b
[doc/book] complete the facet section
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
4751
diff
changeset
|
22 |
|
43d7044f8d0b
[doc/book] complete the facet section
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
4751
diff
changeset
|
23 |
.. automethod:: cubicweb.web.facet.VocabularyFacet.vocabulary |
43d7044f8d0b
[doc/book] complete the facet section
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
4751
diff
changeset
|
24 |
.. automethod:: cubicweb.web.facet.VocabularyFacet.possible_values |
43d7044f8d0b
[doc/book] complete the facet section
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
4751
diff
changeset
|
25 |
|
43d7044f8d0b
[doc/book] complete the facet section
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
4751
diff
changeset
|
26 |
RelationFacet |
43d7044f8d0b
[doc/book] complete the facet section
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
4751
diff
changeset
|
27 |
~~~~~~~~~~~~~~ |
43d7044f8d0b
[doc/book] complete the facet section
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
4751
diff
changeset
|
28 |
|
43d7044f8d0b
[doc/book] complete the facet section
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
4751
diff
changeset
|
29 |
The ``RelationFacet`` inherits from the ``VocabularyFacet``. It allows to filter entities according to certain relation's values. Generally, you just have to define some class attributes like: |
43d7044f8d0b
[doc/book] complete the facet section
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
4751
diff
changeset
|
30 |
|
43d7044f8d0b
[doc/book] complete the facet section
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
4751
diff
changeset
|
31 |
- rtype: the name of the relation |
43d7044f8d0b
[doc/book] complete the facet section
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
4751
diff
changeset
|
32 |
- role: the default value is set to `subject` |
43d7044f8d0b
[doc/book] complete the facet section
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
4751
diff
changeset
|
33 |
- target_attr: needed if it is not the default attribute of the entity |
43d7044f8d0b
[doc/book] complete the facet section
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
4751
diff
changeset
|
34 |
|
43d7044f8d0b
[doc/book] complete the facet section
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
4751
diff
changeset
|
35 |
|
43d7044f8d0b
[doc/book] complete the facet section
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
4751
diff
changeset
|
36 |
To illustrate this facet, let's take for example an *excerpt* of the schema of an office location search application: |
3991
a0aa9789c6bc
Pasting blog about facet in the facet section of the doc book.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
1714
diff
changeset
|
37 |
|
a0aa9789c6bc
Pasting blog about facet in the facet section of the doc book.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
1714
diff
changeset
|
38 |
.. sourcecode:: python |
a0aa9789c6bc
Pasting blog about facet in the facet section of the doc book.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
1714
diff
changeset
|
39 |
|
a0aa9789c6bc
Pasting blog about facet in the facet section of the doc book.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
1714
diff
changeset
|
40 |
class Office(WorkflowableEntityType): |
a0aa9789c6bc
Pasting blog about facet in the facet section of the doc book.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
1714
diff
changeset
|
41 |
price = Int(description='euros / m2 / HC / HT') |
a0aa9789c6bc
Pasting blog about facet in the facet section of the doc book.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
1714
diff
changeset
|
42 |
surface = Int(description='m2') |
a0aa9789c6bc
Pasting blog about facet in the facet section of the doc book.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
1714
diff
changeset
|
43 |
description = RichString(fulltextindexed=True) |
5286
43d7044f8d0b
[doc/book] complete the facet section
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
4751
diff
changeset
|
44 |
has_address = SubjectRelation('PostalAddress', |
43d7044f8d0b
[doc/book] complete the facet section
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
4751
diff
changeset
|
45 |
cardinality='1?', |
43d7044f8d0b
[doc/book] complete the facet section
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
4751
diff
changeset
|
46 |
composite='subject') |
3991
a0aa9789c6bc
Pasting blog about facet in the facet section of the doc book.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
1714
diff
changeset
|
47 |
proposed_by = SubjectRelation('Agency') |
5286
43d7044f8d0b
[doc/book] complete the facet section
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
4751
diff
changeset
|
48 |
comments = ObjectRelation('Comment', |
43d7044f8d0b
[doc/book] complete the facet section
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
4751
diff
changeset
|
49 |
cardinality='1*', |
43d7044f8d0b
[doc/book] complete the facet section
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
4751
diff
changeset
|
50 |
composite='object') |
43d7044f8d0b
[doc/book] complete the facet section
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
4751
diff
changeset
|
51 |
screenshots = SubjectRelation(('File', 'Image'), |
43d7044f8d0b
[doc/book] complete the facet section
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
4751
diff
changeset
|
52 |
cardinality='*1', |
3991
a0aa9789c6bc
Pasting blog about facet in the facet section of the doc book.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
1714
diff
changeset
|
53 |
composite='subject') |
a0aa9789c6bc
Pasting blog about facet in the facet section of the doc book.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
1714
diff
changeset
|
54 |
|
a0aa9789c6bc
Pasting blog about facet in the facet section of the doc book.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
1714
diff
changeset
|
55 |
|
5286
43d7044f8d0b
[doc/book] complete the facet section
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
4751
diff
changeset
|
56 |
We define a facet to filter offices according to the attribute |
43d7044f8d0b
[doc/book] complete the facet section
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
4751
diff
changeset
|
57 |
`postalcode` of their associated `PostalAdress`. |
3991
a0aa9789c6bc
Pasting blog about facet in the facet section of the doc book.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
1714
diff
changeset
|
58 |
|
a0aa9789c6bc
Pasting blog about facet in the facet section of the doc book.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
1714
diff
changeset
|
59 |
.. sourcecode:: python |
a0aa9789c6bc
Pasting blog about facet in the facet section of the doc book.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
1714
diff
changeset
|
60 |
|
4751
1a9d2c3c7f0c
[book] more id -> __regid__
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
4446
diff
changeset
|
61 |
class PostalCodeFacet(RelationFacet): |
5286
43d7044f8d0b
[doc/book] complete the facet section
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
4751
diff
changeset
|
62 |
__regid__ = 'postalcode-facet' # every registered class must have an id |
4751
1a9d2c3c7f0c
[book] more id -> __regid__
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
4446
diff
changeset
|
63 |
__select__ = implements('Office') # this facet should only be selected when |
3991
a0aa9789c6bc
Pasting blog about facet in the facet section of the doc book.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
1714
diff
changeset
|
64 |
# visualizing offices |
a0aa9789c6bc
Pasting blog about facet in the facet section of the doc book.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
1714
diff
changeset
|
65 |
rtype = 'has_address' # this facet is a filter on the entity linked to |
a0aa9789c6bc
Pasting blog about facet in the facet section of the doc book.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
1714
diff
changeset
|
66 |
# the office thrhough the relation |
a0aa9789c6bc
Pasting blog about facet in the facet section of the doc book.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
1714
diff
changeset
|
67 |
# has_address |
a0aa9789c6bc
Pasting blog about facet in the facet section of the doc book.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
1714
diff
changeset
|
68 |
target_attr = 'postalcode' # the filter's key is the attribute "postal_code" |
a0aa9789c6bc
Pasting blog about facet in the facet section of the doc book.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
1714
diff
changeset
|
69 |
# of the target PostalAddress entity |
a0aa9789c6bc
Pasting blog about facet in the facet section of the doc book.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
1714
diff
changeset
|
70 |
|
5286
43d7044f8d0b
[doc/book] complete the facet section
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
4751
diff
changeset
|
71 |
|
43d7044f8d0b
[doc/book] complete the facet section
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
4751
diff
changeset
|
72 |
AttributeFacet |
43d7044f8d0b
[doc/book] complete the facet section
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
4751
diff
changeset
|
73 |
~~~~~~~~~~~~~~ |
3991
a0aa9789c6bc
Pasting blog about facet in the facet section of the doc book.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
1714
diff
changeset
|
74 |
|
5286
43d7044f8d0b
[doc/book] complete the facet section
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
4751
diff
changeset
|
75 |
The ``AttributeFacet`` inherits from the ``RelationFacet``. It allows to filter entities according to certain attribute's values. |
43d7044f8d0b
[doc/book] complete the facet section
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
4751
diff
changeset
|
76 |
|
43d7044f8d0b
[doc/book] complete the facet section
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
4751
diff
changeset
|
77 |
The example below resumes the former schema. We define now a filter based on the `surface` attribute of the |
43d7044f8d0b
[doc/book] complete the facet section
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
4751
diff
changeset
|
78 |
`Office`. |
3991
a0aa9789c6bc
Pasting blog about facet in the facet section of the doc book.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
1714
diff
changeset
|
79 |
|
a0aa9789c6bc
Pasting blog about facet in the facet section of the doc book.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
1714
diff
changeset
|
80 |
.. sourcecode:: python |
a0aa9789c6bc
Pasting blog about facet in the facet section of the doc book.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
1714
diff
changeset
|
81 |
|
a0aa9789c6bc
Pasting blog about facet in the facet section of the doc book.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
1714
diff
changeset
|
82 |
class SurfaceFacet(AttributeFacet): |
5286
43d7044f8d0b
[doc/book] complete the facet section
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
4751
diff
changeset
|
83 |
__regid__ = 'surface-facet' # every registered class must have an id |
4751
1a9d2c3c7f0c
[book] more id -> __regid__
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
4446
diff
changeset
|
84 |
__select__ = implements('Office') # this facet should only be selected when |
3991
a0aa9789c6bc
Pasting blog about facet in the facet section of the doc book.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
1714
diff
changeset
|
85 |
# visualizing offices |
4751
1a9d2c3c7f0c
[book] more id -> __regid__
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
4446
diff
changeset
|
86 |
rtype = 'surface' # the filter's key is the attribute "surface" |
1a9d2c3c7f0c
[book] more id -> __regid__
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
4446
diff
changeset
|
87 |
comparator = '>=' # override the default value of operator since |
3991
a0aa9789c6bc
Pasting blog about facet in the facet section of the doc book.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
1714
diff
changeset
|
88 |
# we want to filter according to a |
4751
1a9d2c3c7f0c
[book] more id -> __regid__
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
4446
diff
changeset
|
89 |
# minimal |
3991
a0aa9789c6bc
Pasting blog about facet in the facet section of the doc book.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
1714
diff
changeset
|
90 |
# value, not an exact one |
a0aa9789c6bc
Pasting blog about facet in the facet section of the doc book.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
1714
diff
changeset
|
91 |
|
a0aa9789c6bc
Pasting blog about facet in the facet section of the doc book.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
1714
diff
changeset
|
92 |
def rset_vocabulary(self, ___): |
a0aa9789c6bc
Pasting blog about facet in the facet section of the doc book.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
1714
diff
changeset
|
93 |
"""override the default vocabulary method since we want to hard-code |
4751
1a9d2c3c7f0c
[book] more id -> __regid__
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
4446
diff
changeset
|
94 |
our threshold values. |
3991
a0aa9789c6bc
Pasting blog about facet in the facet section of the doc book.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
1714
diff
changeset
|
95 |
Not overriding would generate a filter box with all existing surfaces |
a0aa9789c6bc
Pasting blog about facet in the facet section of the doc book.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
1714
diff
changeset
|
96 |
defined in the database. |
a0aa9789c6bc
Pasting blog about facet in the facet section of the doc book.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
1714
diff
changeset
|
97 |
""" |
a0aa9789c6bc
Pasting blog about facet in the facet section of the doc book.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
1714
diff
changeset
|
98 |
return [('> 200', '200'), ('> 250', '250'), |
a0aa9789c6bc
Pasting blog about facet in the facet section of the doc book.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
1714
diff
changeset
|
99 |
('> 275', '275'), ('> 300', '300')] |
a0aa9789c6bc
Pasting blog about facet in the facet section of the doc book.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
1714
diff
changeset
|
100 |
|
5286
43d7044f8d0b
[doc/book] complete the facet section
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
4751
diff
changeset
|
101 |
RangeFacet |
43d7044f8d0b
[doc/book] complete the facet section
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
4751
diff
changeset
|
102 |
~~~~~~~~~~ |
43d7044f8d0b
[doc/book] complete the facet section
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
4751
diff
changeset
|
103 |
The ``RangeFacet`` inherits from the ``AttributeFacet``. It allows to filter entities according to certain attributes of numerical type. |
3991
a0aa9789c6bc
Pasting blog about facet in the facet section of the doc book.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
1714
diff
changeset
|
104 |
|
5286
43d7044f8d0b
[doc/book] complete the facet section
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
4751
diff
changeset
|
105 |
The ``RangeFacet`` displays a slider using `jquery`_ to choose a lower bound and an upper bound. |
3991
a0aa9789c6bc
Pasting blog about facet in the facet section of the doc book.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
1714
diff
changeset
|
106 |
|
5286
43d7044f8d0b
[doc/book] complete the facet section
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
4751
diff
changeset
|
107 |
The example below defines a facet to filter a selection of books according to their number of pages. |
3991
a0aa9789c6bc
Pasting blog about facet in the facet section of the doc book.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
1714
diff
changeset
|
108 |
|
5286
43d7044f8d0b
[doc/book] complete the facet section
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
4751
diff
changeset
|
109 |
.. sourcecode:: python |
3991
a0aa9789c6bc
Pasting blog about facet in the facet section of the doc book.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
1714
diff
changeset
|
110 |
|
5286
43d7044f8d0b
[doc/book] complete the facet section
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
4751
diff
changeset
|
111 |
class BookPagesFacet(RangeFacet): |
43d7044f8d0b
[doc/book] complete the facet section
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
4751
diff
changeset
|
112 |
__regid__ = 'priority-facet' |
43d7044f8d0b
[doc/book] complete the facet section
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
4751
diff
changeset
|
113 |
__select__ = RangeFacet.__select__ & implements('Book') |
43d7044f8d0b
[doc/book] complete the facet section
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
4751
diff
changeset
|
114 |
rtype = 'pages' |
3991
a0aa9789c6bc
Pasting blog about facet in the facet section of the doc book.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
1714
diff
changeset
|
115 |
|
5286
43d7044f8d0b
[doc/book] complete the facet section
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
4751
diff
changeset
|
116 |
The image below display the rendering of the ``RangeFacet``: |
3991
a0aa9789c6bc
Pasting blog about facet in the facet section of the doc book.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
1714
diff
changeset
|
117 |
|
5394
105011657405
[doc/book] move devweb up from development, turn development into devrepo (much better structure)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5286
diff
changeset
|
118 |
.. image:: ../images/facet_range.png |
3991
a0aa9789c6bc
Pasting blog about facet in the facet section of the doc book.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
1714
diff
changeset
|
119 |
|
5286
43d7044f8d0b
[doc/book] complete the facet section
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
4751
diff
changeset
|
120 |
DateRangeFacet |
43d7044f8d0b
[doc/book] complete the facet section
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
4751
diff
changeset
|
121 |
~~~~~~~~~~~~~~ |
43d7044f8d0b
[doc/book] complete the facet section
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
4751
diff
changeset
|
122 |
The ``DateRangeFacet`` inherits from the ``RangeFacet``. It allows to filter entities according to certain attributes of date type. |
3991
a0aa9789c6bc
Pasting blog about facet in the facet section of the doc book.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
1714
diff
changeset
|
123 |
|
5286
43d7044f8d0b
[doc/book] complete the facet section
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
4751
diff
changeset
|
124 |
Here is an example of code that defines a facet to filter |
3991
a0aa9789c6bc
Pasting blog about facet in the facet section of the doc book.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
1714
diff
changeset
|
125 |
musical works according to their composition date: |
a0aa9789c6bc
Pasting blog about facet in the facet section of the doc book.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
1714
diff
changeset
|
126 |
|
a0aa9789c6bc
Pasting blog about facet in the facet section of the doc book.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
1714
diff
changeset
|
127 |
.. sourcecode:: python |
a0aa9789c6bc
Pasting blog about facet in the facet section of the doc book.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
1714
diff
changeset
|
128 |
|
a0aa9789c6bc
Pasting blog about facet in the facet section of the doc book.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
1714
diff
changeset
|
129 |
class CompositionDateFacet(DateRangeFacet): |
a0aa9789c6bc
Pasting blog about facet in the facet section of the doc book.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
1714
diff
changeset
|
130 |
# 1. make sure this facet is displayed only on Track selection |
a0aa9789c6bc
Pasting blog about facet in the facet section of the doc book.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
1714
diff
changeset
|
131 |
__select__ = DateRangeFacet.__select__ & implements('Track') |
4446
a413fac5ff5e
damn me, more stupid sed fix...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4437
diff
changeset
|
132 |
# 2. give the facet an id required by CubicWeb) |
4751
1a9d2c3c7f0c
[book] more id -> __regid__
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
4446
diff
changeset
|
133 |
__regid__ = 'compdate-facet' |
3991
a0aa9789c6bc
Pasting blog about facet in the facet section of the doc book.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
1714
diff
changeset
|
134 |
# 3. specify the attribute name that actually stores the date in the DB |
a0aa9789c6bc
Pasting blog about facet in the facet section of the doc book.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
1714
diff
changeset
|
135 |
rtype = 'composition_date' |
a0aa9789c6bc
Pasting blog about facet in the facet section of the doc book.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
1714
diff
changeset
|
136 |
|
5286
43d7044f8d0b
[doc/book] complete the facet section
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
4751
diff
changeset
|
137 |
With this facet, on each page displaying tracks, you'll be able to filter them |
3991
a0aa9789c6bc
Pasting blog about facet in the facet section of the doc book.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
1714
diff
changeset
|
138 |
according to their composition date with a jquery slider. |
a0aa9789c6bc
Pasting blog about facet in the facet section of the doc book.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
1714
diff
changeset
|
139 |
|
5286
43d7044f8d0b
[doc/book] complete the facet section
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
4751
diff
changeset
|
140 |
The image below display the rendering of the ``DateRangeFacet``: |
43d7044f8d0b
[doc/book] complete the facet section
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
4751
diff
changeset
|
141 |
|
5394
105011657405
[doc/book] move devweb up from development, turn development into devrepo (much better structure)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5286
diff
changeset
|
142 |
.. image:: ../images/facet_date_range.png |
5286
43d7044f8d0b
[doc/book] complete the facet section
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
4751
diff
changeset
|
143 |
|
43d7044f8d0b
[doc/book] complete the facet section
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
4751
diff
changeset
|
144 |
|
43d7044f8d0b
[doc/book] complete the facet section
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
4751
diff
changeset
|
145 |
HasRelationFacet |
43d7044f8d0b
[doc/book] complete the facet section
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
4751
diff
changeset
|
146 |
~~~~~~~~~~~~~~~~ |
43d7044f8d0b
[doc/book] complete the facet section
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
4751
diff
changeset
|
147 |
|
43d7044f8d0b
[doc/book] complete the facet section
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
4751
diff
changeset
|
148 |
The ``DateRangeFacet`` inherits from the ``AbstractFacet``. It will |
43d7044f8d0b
[doc/book] complete the facet section
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
4751
diff
changeset
|
149 |
display a simple checkbox and lets you refine your selection in order |
43d7044f8d0b
[doc/book] complete the facet section
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
4751
diff
changeset
|
150 |
to get only entities that actually use this relation. |
43d7044f8d0b
[doc/book] complete the facet section
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
4751
diff
changeset
|
151 |
|
43d7044f8d0b
[doc/book] complete the facet section
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
4751
diff
changeset
|
152 |
Here is an example of the rendering of the ``HasRelationFacet`` to |
43d7044f8d0b
[doc/book] complete the facet section
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
4751
diff
changeset
|
153 |
filter entities with image and the corresponding code: |
43d7044f8d0b
[doc/book] complete the facet section
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
4751
diff
changeset
|
154 |
|
5394
105011657405
[doc/book] move devweb up from development, turn development into devrepo (much better structure)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5286
diff
changeset
|
155 |
.. image:: ../images/facet_has_image.png |
5286
43d7044f8d0b
[doc/book] complete the facet section
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
4751
diff
changeset
|
156 |
|
43d7044f8d0b
[doc/book] complete the facet section
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
4751
diff
changeset
|
157 |
.. sourcecode:: python |
43d7044f8d0b
[doc/book] complete the facet section
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
4751
diff
changeset
|
158 |
|
43d7044f8d0b
[doc/book] complete the facet section
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
4751
diff
changeset
|
159 |
class HasImageFacet(HasRelationFacet): |
43d7044f8d0b
[doc/book] complete the facet section
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
4751
diff
changeset
|
160 |
__regid__ = 'hasimage-facet' |
43d7044f8d0b
[doc/book] complete the facet section
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
4751
diff
changeset
|
161 |
__select__ = HasRelationFacet.__select__ & implements('Book') |
43d7044f8d0b
[doc/book] complete the facet section
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
4751
diff
changeset
|
162 |
rtype = 'has_image' |
43d7044f8d0b
[doc/book] complete the facet section
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
4751
diff
changeset
|
163 |
|
43d7044f8d0b
[doc/book] complete the facet section
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
4751
diff
changeset
|
164 |
|
43d7044f8d0b
[doc/book] complete the facet section
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
4751
diff
changeset
|
165 |
|
43d7044f8d0b
[doc/book] complete the facet section
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
4751
diff
changeset
|
166 |
To use ``HasRelationFacet`` on a reverse relation add ``role = 'object'`` in |
43d7044f8d0b
[doc/book] complete the facet section
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
4751
diff
changeset
|
167 |
it's definitions. |
3991
a0aa9789c6bc
Pasting blog about facet in the facet section of the doc book.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
1714
diff
changeset
|
168 |
|
a0aa9789c6bc
Pasting blog about facet in the facet section of the doc book.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
1714
diff
changeset
|
169 |
.. _facet: http://en.wikipedia.org/wiki/Faceted_browser |
a0aa9789c6bc
Pasting blog about facet in the facet section of the doc book.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
1714
diff
changeset
|
170 |
.. _filters: http://www.cubicweb.org/blogentry/154152 |
a0aa9789c6bc
Pasting blog about facet in the facet section of the doc book.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
1714
diff
changeset
|
171 |
.. _jquery: http://www.jqueryui.com/ |
a0aa9789c6bc
Pasting blog about facet in the facet section of the doc book.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
1714
diff
changeset
|
172 |