Changes between Version 7 and Version 8 of S3/S3ResourceFilter


Ignore:
Timestamp:
01/31/12 13:48:08 (10 years ago)
Author:
Dominic König
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • S3/S3ResourceFilter

    v7 v8  
    8585}}}
    8686
    87 The '''value''' can be a single value, a comma-separated list of values. NONE specifies a null-value (undefined, Python None). Values in quotes are treated as strings, i.e.
     87The '''value''' can be a single value, a comma-separated list of values.
     88
     89Date-time-values must be specified as YYYY-MM-DDThh:mm:ss, dates as YYYY-MM-DD and times as hh:mm:ss. Other types use their standard Python notation. NONE specifies a null-value (undefined, Python None). Values in quotes are treated as strings, i.e.
    8890
    8991{{{
     
    101103It is currently not possible to escape quotation marks in order to enclose them in strings - thus strings must not contain quotation marks.
    102104
    103 For all operators except __belongs, any comma-separated lists of values are treated as alternatives (OR) ''unless'' the field contains a list as well. All operators except __like are case-sensitive.
     105For all operators except !__belongs, any comma-separated lists of values are treated as alternatives (OR) ''unless'' the field contains a list as well. All operators except !__like are case-sensitive.
    104106
    105107== Extending filters at the back-end ==
    106108
     109S3QueryField instances can also be generated at the back-end, simply by:
     110
     111{{{
     112selector = S3QueryField(<field selector>)
     113}}}
     114
     115Such selectors can then be used to create filter queries, using a syntax very similar to web2py queries:
     116
     117{{{
     118afilter = S3QueryField("person.first_name") == "Dominic"
     119bfilter = ~(S3QueryField("person.first_name").like("Dominic"))  # negation by ~ operator
     120}}}
     121
     122The equivalent query operators are:
     123
     124||'''Python Operator'''||'''URL Operator'''||
     125||{{{<}}}||!__lt||
     126||{{{<=}}}||!__le||
     127||{{{==}}}||!__eq||
     128||{{{!=}}}||!__ne||
     129||{{{>=}}}||!__ge||
     130||{{{>}}}||!__gt||
     131||{{{.like()}}}||!__like||
     132||{{{.contains()}}}||!__contains||
     133||{{{.belongs()}}}||!__belongs||
     134
     135These filter queries can also be joined together by {{{&}}} and {{{|}}} operators:
     136
     137{{{
     138cfilter = (S3QueryField("person.first_name") == "Dominic") & (S3QueryField("contact.value") == "dominic@nursix.org")
     139}}}
     140
     141Note: be diligent with brackets here ({{{&}}} and {{{|}}} operators take precedence).
     142
     143To add a filter to a resource is as simple as:
     144
     145{{{
     146myfilter = S3QueryField("person.first_name") == "Dominic"
     147resource.add_filter(myfilter)
     148}}}
     149
     150Note that filters (S3ResourceQuery instances) are resource-agnostic, so they can be re-used across resources (provided the same field selector applies in all of them).
     151
     152Filters for fields which are not defined in a resource will be ignored quietly when retrieving records from the resource.