Changes between Version 89 and Version 90 of S3/S3REST/s3_rest_controller

09/09/21 10:37:55 (2 years ago)
Fran Boon

Custom REST Controllers


  • S3/S3REST/s3_rest_controller

    v89 v90  
    698698And...not to forget: your warehouse_report is still a controller function, that means you can implement forms as usual (e.g. operated with form.accepts or web2py Crud).
     700=== Re-Routing Controllers ===
     701There may be a time when you want to bypass the default controllers, or else add a custom controller which can have different options.
     703This allows re-routing of any controller/function combination to the custom/rest controller - which is a vanilla s3_rest_controller, i.e. without any prep, postp or attr. The latter can then be added in customise_controller.
     705To use this, a template will configure e.g.:
     708settings.base.rest_controllers = {("org", "organisation"): ("org", "organisation")}
     710...which re-routes org/organisation to custom/rest, and runs it as a s3_rest_controller with prefix="org" and name="organisation". This re-routing is completely transparent, i.e. the s3_rest_controller (and anything called from there) sees a normal org/organisation request. Consequently, to customise this call, one would use customise_org_organisation_controller (not customise_custom_rest_controller!), as usual.
     712As this allows re-routing of any controller/function combination, one can also "add" controllers that do not exist, e.g.:
     715settings.base.rest_controllers = {("org", "suppliers"): ("org", "organisation")}
     717This would though still be customised via customise_org_organisation_controller (=>can inspect r.function in prep to distinguish), but page access authorisation would now be through org/suppliers rather than org/organisation (so can have different permissions for those).
     719When adding a route with a custom module prefix:
     722settings.base.rest_controllers = {("my", "organisation"): ("org", "organisation")}
     724...then a corresponding module entry for that must be added to settings.modules - though this is useful anyway if menus are to be added automatically etc. Again, page authorisation would go through my/organisation here instead of org/organisation, so there could be different permission sets.
     726Note: this feature is orthogonal to default/index/*, which is still useful for implementing non-REST custom controllers, and should therefore be retained.