| 12 | === Method Handlers === |
| 13 | |
| 14 | The default method handlers for each of CRUD+S are implemented in models/01_RESTlike_controller.py: |
| 15 | |
| 16 | - shn_read(jr, **attr) |
| 17 | - shn_list(jr, **attr) |
| 18 | - shn_create(jr, **attr) |
| 19 | - shn_update(jr, **attr) |
| 20 | - shn_delete(jr, **attr) |
| 21 | - shn_search(jr, **attr) |
| 22 | - shn_options(jr, **attr) |
| 23 | - import_xml(jr, **attr) |
| 24 | - import_json(jr, **attr) |
| 25 | |
| 26 | where ''jr'' is the current ''XRequest'', and ''**attr'' contains all further arguments passed to the REST controller. |
| 27 | |
| 28 | You can override these defaults at any time by |
| 29 | {{{ |
| 30 | s3rest.set_handler(action, handler) |
| 31 | }} |
| 32 | where: |
| 33 | |
| 34 | - '''action''' is the name of the action, i.e. one of 'read', 'list', 'create', 'update', 'delete', 'search', 'options', 'import_xml' or 'import_json' |
| 35 | - '''handler''' is the handler function/lambda |
| 36 | |
| 37 | === Custom Methods === |
| 38 | |
| 39 | You can also add resource-specific custom actions by: |
| 40 | {{{ |
| 41 | s3xrc.model.set_method(module, resource, method, action) |
| 42 | }}} |
| 43 | where: |
| 44 | |
| 45 | - '''module''' is the module prefix of a resource |
| 46 | - '''resource''' is the name of the resource (without prefix) |
| 47 | - '''method''' is a string representing the name of the method (e.g. "search_simple") |
| 48 | - '''action''' is the method handler function/lambda |
| 49 | |
| 50 | The ''action'' method has to take the same arguments as the default handlers: ''jr'' (XRequest) and ''**attr''. |