Version 4 (modified by Dominic König, 10 years ago) ( diff )


BluePrint: RESTful Search Methods


  • coming soon


  • coming soon


  • coming soon


  • coming soon



The S3Find class implements the S3Method interface, and is connected to the search URL method:


S3Find implements both, interactive and non-interactive search methods. Currently supported formats are:

  • HTML
  • JSON

There is a generic S3Find default instance connected to all resources, which will be used unless there is a resource-specific instance configured. However, this default instance does not provide any interactive search methods (JSON only).

To connect a custom S3Find instance to a resource (in order to add interactive search methods), use s3xrc.model.configure:

s3xrc.model.configure(table, search_method=my_s3find_instance

See the next paragraph for how to build and connect a custom S3Find instance for a resource.

Interactive search methods

For interactive search, S3Find can be configured per resource, using instances of classes implementing the S3SearchWidget interface to create search forms.

Two interactive search forms can be configured (both of which are optional): simple and advanced, where the user can toggle between these forms (if both are defined).

    # Use a variable to hold the S3Find instance
    hms_hospital_search = s3base.S3Find(

        # Simple search form as a tuple of widgets:
                  # simple full-text search widget:
                    name="hospital_search_advanced",             # widget name must be specified and unique in the form!
                    label=T("Name and/or ID"),                   # Label for the search field
                    comment=T("To search for a hospital, ..."),  # Tooltip text for the search field
                    field=["paho_uuid",                          # Names of fields to search in
                  ), # <-- note the comma!

        # Advanced search form as a tuple of widgets:

                  # simple full-text search widget:
                    label=T("Name, Org and/or ID"),
                    comment=T("To search for a hospital, ..."),
                           "",                       # "." separator: search in component
                           "organisation_id$name",               # "$" separator: search in records referenced by organisation_id

                  # MinMax search widget to filter for a range of values:
                    method="range",                              # widget-specific attribute "method"
                    label=T("Total Beds"),
                    comment=T("Select a range for the ..."),
                    field="total_beds"                           # most widgets only support one search field

    # Set as standard search method for this resource
    s3xrc.model.configure(db.hms_hospital, search_method=hms_hospital_search)

The simple form usually consists of a S3SearchSimpleWidget which performs a simple full-text search through various fields of the resource. However, the simple form may also be configured with other search widgets. In the same manner, the advanced form can include the S3SearchSimpleWidget.

When calling the search method, the simple form will be opened first, while the advanced form is hidden (if only the advanced form is defined, then it will of course not be hidden). By clicking the Advanced Search link below the form, the user can switch to the advanced form, and vice versa. The forms are independent, i.e. the user can only submit one of them.


  • modules/s3/


Note: See TracWiki for help on using the wiki.