wiki:S3/S3Request

Version 1 (modified by Dominic König, 11 years ago) ( diff )

--

S3XRC - S3Request

S3Request and Method Handlers

When method handlers are called by the REST interface, they get a S3Request object passed as the first argument, usually named "r" or "jr":

def method_handler(r, **attr):

This S3Request instance represents the request to be executed, and it contains references to all data necessary to perform the requested action.

Note: All method handlers receive the same list of arguments, regardless of whether they are standard CRUD or custom method handlers.

Attributes of the S3Request

The following attributes are set during initialisation of an S3Request object, no further call is required.

Controller Attributes

rcthe resource controller object (S3ResourceController)
requestthe original web2py request (Storage)
sessionthe current session (Storage)
responsethe web2py response (Storage)

Request Attributes

representationthe current representation of this request (string, lowercase)
httpthe HTTP method of this request (string, always uppercase!)
extensionthe extension found in the original request (string, lowercase)
methodthe method of the request if not HTTP (string, always lowercase)
custom_actionthe custom method handler for the request (function or lambda)

Primary Resource Attributes

prefixthe prefix (=module name) of the requested resource (string)
namethe name of the requested resource, without prefix (string)
tablenamethe name of the primary table (string)
tablethe primary table (Table)
idthe ID of the primary record (int)
recordthe primary record (Row)

Component Resource Attributes

componentthe requested component, if any (ObjectComponent)
pkeythe primary key of the Resource/Component join (string)
fkeythe foreign key of the Resource/Component join (string)
component_namethe name of the component without prefix (string)
component_idthe ID of the component record as of the request, if any (int)
multipleFlag indicating that multiple component records are allowed (boolean)

Error Indicators

errorthe last error message (string)
invalidFlag indicating this request as invalid (boolean)
badmethodFlag indicating a bad method error (boolean)
badrecordFlag indicating a invalid record ID error (boolean)
badrequestFlag indicating an unqualified request error (boolean)

ObjectComponent contains:

  • prefix, name, tablename, table and attr of the component
  • attr contains:
    • multiple Multiple-flag
    • editable, deletable and listadd
    • list_fields, rss, main and extra
    • onaccept, onvalidation, delete_onaccept and delete_onvalidation
  • methods: set_attr() and get_attr()

Methods of the S3Request

Magic URLs

here(representation=None)

  • returns the URL of the current request

there(representation=None)

  • returns the URL of a HTTP GET request for the same resource

same(representation=None)

  • returns the URL of the current request with the primary record ID replaced by the string literal '[id]'

other(method=None, record_id=None, representation=None)

  • returns the URL of a request with another method and record ID, but for the same resource

Other functions

target()

  • returns the target table of the current request as tuple of (prefix, name, table, tablename)
Note: See TracWiki for help on using the wiki.