doc/book/en/development/devweb/facets.rst
author Pierre-Yves David <pierre-yves.david@logilab.fr>
Thu, 03 Dec 2009 09:50:51 +0100
branchstable
changeset 3991 a0aa9789c6bc
parent 1714 a721966779be
child 4437 21f2e01fdd6a
permissions -rw-r--r--
Pasting blog about facet in the facet section of the doc book.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
-----------------
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
     3
XXX feed me more (below is the extracted of adim blog)
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
     4
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
     5
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
     6
Recently, for internal purposes, we've made a little cubicweb application 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
     7
help us
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
     8
organizing visits to find new office locations. Here's an *excerpt* of the
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
     9
schema:
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
    10
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
    11
.. 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
    12
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
    13
  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
    14
      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
    15
      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
    16
      description = RichString(fulltextindexed=True)
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
      has_address = SubjectRelation('PostalAddress', cardinality='1?', 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
    18
      proposed_by = SubjectRelation('Agency')
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
    19
      comments = ObjectRelation('Comment', cardinality='1*', composite='object')
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
    20
      screenshots = SubjectRelation(('File', 'Image'), cardinality='*1',
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
    21
                                    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
    22
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
    23
The two other entity types defined in the schema are `Visit` and `Agency` but we
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
    24
can also guess from the above that this application uses the two cubes
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
    25
`comment`_ and
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
    26
`addressbook`_ (remember, cubicweb is only a game where you assemble cubes !). 
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
    27
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
    28
While we know that just defining the schema in enough to have a full, usable,
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
    29
(testable !) application, we also know that every application needs to be 
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
    30
customized to fulfill the needs it was built for. So in this case, what we
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
    31
needed most was some custom filters that would let us restrict searches
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
    32
according
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
    33
to surfaces, prices or zipcodes. Fortunately for us, Cubicweb provides the
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
    34
**facets** (image_) mechanism and a few base classes that make the task quite
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
    35
easy:
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
    36
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
.. 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
    38
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
  class PostalCodeFacet(RelationFacet): 
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
      id = 'postalcode-facet'             # every registered class must have an id
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
      __select__ = implements('Office')   # this facet should only be selected when 
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
                                          # 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
    43
      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
    44
                                          # 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
    45
                                          # 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
    46
      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
    47
                                          # 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
    48
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
    49
This is a typical `RelationFacet`: we want to be able to filter 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
    50
according
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
    51
to the attribute `postalcode` of their associated `PostalAdress`. Each line in
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
    52
the class is explained by the comment on its right.
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
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
Now, here is the code to define a filter based on the `surface` attribute of the
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
`Office`:
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
    56
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
    57
.. 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
    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
  class SurfaceFacet(AttributeFacet):
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
      id = 'surface-facet'              # every registered class must have an id
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
    61
      __select__ = implements('Office') # this facet should only be selected when 
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
    62
                                        # 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
    63
      rtype = 'surface'                 # the filter's key is the attribute "surface" 
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
      comparator = '>='                 # override the default value of operator since 
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
                                        # we want to filter according to a
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
                                        # minimal 
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
                                        # 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
    68
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
      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
    70
          """override the default vocabulary method since we want to hard-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
    71
          our threshold values. 
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
    72
          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
    73
          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
    74
          """
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
    75
          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
    76
                  ('> 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
    77
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
    78
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
And that's it: we have two filter boxes automatically displayed on each page
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
presenting more than one office. The `price` facet is basically the same as the
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
`surface` one but with a different vocabulary and with ``rtype = 'price'``.
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
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
    83
(The cube also benefits from the builtin google map views defined by
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
    84
cubicweb but that's for another blog).
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
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
    86
.. _image: http://www.cubicweb.org/image/197646?vid=download
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
    87
.. _comment: http://www.cubicweb.org/project/cubicweb-comment
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
.. _addressbook: http://www.cubicweb.org/project/cubicweb-addressbook
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
    89
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
CubicWeb has this really nice builtin `facet`_ system 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
    91
define restrictions `filters`_ really as easily as possible.
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
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
We've just added two new kind of facets in CubicWeb :
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
    94
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
- The **RangeFacet** which displays a slider using `jquery`_
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
  to choose a lower bound and an upper bound. The **RangeWidget** 
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
  works with either numerical values or date values
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
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
- The **HasRelationFacet** which displays a simple checkbox and
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
  lets you refine your selection in order to get only entities
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
   101
  that actually use this 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
   102
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
   103
.. image :: http://www.cubicweb.org/Image/343498?vid=download
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
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
   105
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
Here's an example of code that defines a facet to filter 
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
   107
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
   108
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
   109
.. 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
   110
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
   111
    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
   112
        # 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
   113
        __select__ = DateRangeFacet.__select__ & implements('Track')
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
   114
        # 2. give the facet an id (required by CubicWeb)
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
        id = 'compdate-facet'
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
   116
        # 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
   117
        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
   118
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
And that's it, on each page displaying tracks, you'll be able to filter them
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
   120
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
   121
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
   122
All this, brought by CubicWeb (in the next 3.3 version)
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
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
   124
.. _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
   125
.. _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
   126
.. _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
   127
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
To use **HasRelationFacet** on a reverse relation add ``role = 'object'`` in
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
it's definitions.