doc/book/en/development/devcore/selectors.rst
branchtls-sprint
changeset 1714 a721966779be
child 2175 16d3c37c5d28
equal deleted inserted replaced
1499:fd8751c3f3ee 1714:a721966779be
       
     1 Base selectors
       
     2 --------------
       
     3 
       
     4 Selectors are scoring functions that are called by the view dispatcher to tell
       
     5 whenever a view can be applied to a given result set of a request. Selector sets
       
     6 are the glue that tie views to the data model. Using them appropriately is an
       
     7 essential part of the construction of well behaved cubes.
       
     8 
       
     9 
       
    10 `CubicWeb` provides its own set of selectors that you can use and here is a
       
    11 description of some of the most common used:
       
    12 
       
    13 Of course you will write your own set of selectors as you get familiar with the
       
    14 framework.
       
    15 
       
    16 
       
    17 :yes([score=1]):
       
    18   Return the score given as parameter (default to 1). Usually used for appobjects
       
    19   which can be selected whatever the context, or also sometimes to add arbitrary
       
    20   points to a score. Take care, `yes(0)` could be named 'no'...
       
    21 
       
    22 
       
    23 Rset selectors
       
    24 ~~~~~~~~~~~~~~
       
    25 :none_rset():
       
    26   Return 1 if the result set is None.
       
    27 
       
    28 :any_rset():
       
    29   Return 1 for any result set, whatever the number of rows in it.
       
    30 
       
    31 :nonempty_rset():
       
    32   Return 1 for non empty result set.
       
    33 
       
    34 :empty_rset():
       
    35   Return 1 for empty result set.
       
    36 
       
    37 :one_line_rset():
       
    38   Return 1 if the result set is of size 1 or if a row is specified.
       
    39 
       
    40 :two_lines_rset():
       
    41   Return 1 if the result set has *at least* two rows.
       
    42 
       
    43 :two_cols_rset():
       
    44   Return 1 if the result set is not empty and has *at least* two columns per
       
    45   row.
       
    46 
       
    47 :paginated_rset():
       
    48   Return 1 if the result set has more rows the specified by the
       
    49   `navigation.page-size` property.
       
    50 
       
    51 :sorted_rset():
       
    52   Return 1 if the result set has an ORDERBY clause.
       
    53 
       
    54 :one_etype_rset():
       
    55   Return 1 if the result set has entities which are all of the same type in a
       
    56   given column (default to column 0).
       
    57 
       
    58 :non_final_entity():
       
    59   Return 1 if the result set contains entities in a given column (the first one
       
    60   by default), and no "final" values such as string of int.
       
    61 
       
    62 :implements(<iface or etype>, ...):
       
    63   Return positive score if entities in the result set are of the given entity
       
    64   type or implements given interface.  If multiple arguments are given, matching
       
    65   one of them is enough. Returned score reflects the "distance" between expected
       
    66   type or interface and matched entities. Entity types are usually given as
       
    67   string, the corresponding class will be fetched from the vregistry.
       
    68 
       
    69 :two_etypes_rset(): XXX
       
    70 :entity_implements(): XXX
       
    71 :relation_possible(): XXX
       
    72 :partial_relation_possible(): XXX
       
    73 :may_add_relation(): XXX
       
    74 :partial_may_add_relation(): XXX
       
    75 :has_related_entities(): XXX
       
    76 :partial_has_related_entities(): XXX
       
    77 :has_permission(): XXX
       
    78 :has_add_permission(): XXX
       
    79 :rql_condition(): XXX
       
    80 :but_etype(): XXX
       
    81 :score_entity(): XXX
       
    82 
       
    83 Request selectors
       
    84 ~~~~~~~~~~~~~~~~~~
       
    85 :anonymous_user():
       
    86   Return 1 if user isn't authenticated (eg is the anonymous user).
       
    87 
       
    88 :authenticated_user():
       
    89   Return 1 if user is authenticated.
       
    90 
       
    91 :match_user_groups(): XXX
       
    92 :match_search_state(): XXX
       
    93 :match_form_params(): XXX
       
    94 
       
    95 Other selectors
       
    96 ~~~~~~~~~~~~~~~
       
    97 :match_kwargs(): XXX
       
    98 :match_context_prop(): XXX
       
    99 :appobject_selectable(): XXX
       
   100 :specified_etype_implements(): XXX
       
   101 :primary_view(): XXX