| 1 | [[TOC]] |
| 2 | = S3XRC - S3Request = |
| 3 | |
| 4 | - [wiki:S3XRC] |
| 5 | |
| 6 | == S3Request and Method Handlers == |
| 7 | |
| 8 | When method handlers are called by the [wiki:S3XRC_S3Resource#RESTInterface REST interface], they get a S3Request object passed as the first argument, usually named "r" or "jr": |
| 9 | |
| 10 | {{{ |
| 11 | def method_handler(r, **attr): |
| 12 | }}} |
| 13 | |
| 14 | This S3Request instance represents the request to be executed, and it contains references to all data necessary to perform the requested action. |
| 15 | |
| 16 | ''Note: All method handlers receive the same list of arguments, regardless of whether they are standard CRUD or custom method handlers.'' |
| 17 | == Attributes of the S3Request == |
| 18 | |
| 19 | The following attributes are set during initialisation of an S3Request object, no further call is required. |
| 20 | |
| 21 | === Controller Attributes === |
| 22 | |
| 23 | ||'''rc'''||the resource controller object (''S3ResourceController'')|| |
| 24 | ||'''request'''||the original web2py request (''Storage'')|| |
| 25 | ||'''session'''||the current session (''Storage'')|| |
| 26 | ||'''response'''||the web2py response (''Storage'')|| |
| 27 | |
| 28 | === Request Attributes === |
| 29 | |
| 30 | ||'''representation'''||the current representation of this request (''string'', lowercase)|| |
| 31 | ||'''http'''||the HTTP method of this request (''string'', always uppercase!)|| |
| 32 | ||'''extension'''||the extension found in the original request (''string'', lowercase)|| |
| 33 | ||'''method'''||the method of the request if not HTTP (''string'', always lowercase)|| |
| 34 | ||'''custom_action'''||the custom method handler for the request (''function'' or ''lambda'')|| |
| 35 | |
| 36 | === Primary Resource Attributes === |
| 37 | |
| 38 | ||'''prefix'''||the prefix (=module name) of the requested resource (''string'')|| |
| 39 | ||'''name'''||the name of the requested resource, without prefix (''string'')|| |
| 40 | ||'''tablename'''||the name of the primary table (''string'')|| |
| 41 | ||'''table'''||the primary table (''Table'')|| |
| 42 | ||'''id'''||the ID of the primary record (''int'')|| |
| 43 | ||'''record'''||the primary record (''Row'')|| |
| 44 | |
| 45 | === Component Resource Attributes === |
| 46 | |
| 47 | ||'''component'''||the requested component, if any (''!ObjectComponent'')|| |
| 48 | ||'''pkey'''||the primary key of the Resource/Component join (''string'')|| |
| 49 | ||'''fkey'''||the foreign key of the Resource/Component join (''string'')|| |
| 50 | ||'''component_name'''||the name of the component without prefix (''string'')|| |
| 51 | ||'''component_id'''||the ID of the component record as of the request, if any (''int'')|| |
| 52 | ||'''multiple'''||Flag indicating that multiple component records are allowed (''boolean'')|| |
| 53 | |
| 54 | === Error Indicators === |
| 55 | |
| 56 | ||'''error'''||the last error message (''string'')|| |
| 57 | ||'''invalid'''||Flag indicating this request as invalid (''boolean'')|| |
| 58 | ||'''badmethod'''||Flag indicating a bad method error (''boolean'')|| |
| 59 | ||'''badrecord'''||Flag indicating a invalid record ID error (''boolean'')|| |
| 60 | ||'''badrequest'''||Flag indicating an unqualified request error (''boolean'')|| |
| 61 | |
| 62 | '''!ObjectComponent''' contains: |
| 63 | - '''prefix''', '''name''', '''tablename''', '''table''' and '''attr''' of the component |
| 64 | - '''attr''' contains: |
| 65 | - '''multiple''' Multiple-flag |
| 66 | - '''editable''', '''deletable''' and '''listadd''' |
| 67 | - '''list_fields''', '''rss''', '''main''' and '''extra''' |
| 68 | - '''onaccept''', '''onvalidation''', '''delete_onaccept''' and '''delete_onvalidation''' |
| 69 | - methods: '''set_attr()''' and '''get_attr()''' |
| 70 | |
| 71 | == Methods of the S3Request == |
| 72 | |
| 73 | === Magic URLs === |
| 74 | |
| 75 | '''here(representation=None)''' |
| 76 | - returns the URL of the current request |
| 77 | |
| 78 | '''there(representation=None)''' |
| 79 | - returns the URL of a HTTP GET request for the same resource |
| 80 | |
| 81 | '''same(representation=None)''' |
| 82 | - returns the URL of the current request with the primary record ID replaced by the string literal '[id]' |
| 83 | |
| 84 | '''other(method=None, record_id=None, representation=None)''' |
| 85 | - returns the URL of a request with another method and record ID, but for the same resource |
| 86 | |
| 87 | === Other functions === |
| 88 | |
| 89 | '''target()''' |
| 90 | - returns the target table of the current request as tuple of (prefix, name, table, tablename) |
| 91 | |