Changes between Version 51 and Version 52 of S3/S3REST/URLFormat


Ignore:
Timestamp:
04/09/20 13:17:32 (5 years ago)
Author:
Fran Boon
Comment:

Example of doing a negative component search by creating a custom component

Legend:

Unmodified
Added
Removed
Modified
  • S3/S3REST/URLFormat

    v51 v52  
    112112
    113113Find persons whose first name starts with "Mir":
    114 
    115114{{{
    116115/pr/person?person.first_name__like=Mir*
     
    118117
    119118The tilde {{{~}}} refers to the master resource addressed by the URL, i.e. this one is equivalent to the former:
    120 
    121119{{{
    122120/pr/person?~.first_name__like=Mir*
     
    124122
    125123Find offices with location names which start with "Osl":
    126 
    127124{{{
    128125/org/office?~.location_id$name__like=Osl*
     
    130127
    131128Query operators can be negated by inserting a {{{!}}}, i.e. find offices with location names which do ''not'' start with "Osl":
    132 
    133129{{{
    134130/org/office?~.location_id$name__like!=Osl*
    135131}}}
     132
     133Find all people *without* a specific [set of] qualification(s):
     134
     135This isn't supported out of the box, as it cannot be done with WHERE clause(s). However it is easy to do it with a little custom code:
     136{{{
     137def customise_pr_person_resource(r, tablename):
     138    # Filtered Component to allow an exclusive filter
     139    s3db = current.s3db
     140    ctable = s3db.hrm_certificate
     141    query = (ctable.name.like("Fire%")) & \
     142            (ctable.deleted == False)
     143    rows = current.db(query).select(stable.id)
     144    fire_cert_ids = [row.id for row in rows]
     145    s3db.add_components("pr_person",
     146                        hrm_certification = {"name": "missing_qualification",
     147                                             "joinby": "person_id",
     148                                             "filterby": {"certificate_id": fire_cert_ids},
     149                                             },
     150                        )
     151settings.customise_pr_person_resource = customise_pr_person_resource
     152}}}
     153
     154Then you can do:
     155{{{
     156/pr/person?missing_qualification.id=None*
     157}}}
     158(This can be then further refined using standard UI Filter Widgets)
    136159
    137160== Bracketed OR Queries ==