Package s3 :: Module s3rest :: Class S3Request
[frames] | no frames]

Class S3Request

source code

object --+
         |
        S3Request

Class to handle RESTful requests

Instance Methods
 
__init__(self, prefix=None, name=None, r=None, c=None, f=None, args=None, vars=None, extension=None, get_vars=None, post_vars=None, http=None)
Constructor
source code
 
set_handler(self, method, handler, http=None, representation=None, transform=False)
Set a method handler for this request
source code
 
get_handler(self, method, transform=False)
Get a method handler for this request
source code
 
get_widget_handler(self, method)
Get the widget handler for a method
source code
 
__call__(self, **attr)
Execute this request
source code
 
factory(self, **args)
Generate a new request for the same resource
source code
 
__getattr__(self, key)
Called upon S3Request.<key> - looks up the value for the <key> attribute.
source code
 
transformable(self, method=None)
Check the request for a transformable format
source code
 
actuate_link(self, component_id=None)
Determine whether to actuate a link or not
source code
 
error(self, status, message, tree=None, next=None)
Action upon error
source code
 
url(self, id=None, component=None, component_id=None, target=None, method=None, representation=None, vars=None, host=None)
Returns the URL of this request, use parameters to override current requests attributes:
source code
 
target(self)
Get the target table of the current request
source code
 
stylesheet(self, method=None, skip_error=False)
Find the XSLT stylesheet for this request
source code
 
read_body(self)
Read data from request body
source code
 
customise_resource(self, tablename=None)
Invoke the customization callback for a resource.
source code

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Static Methods
 
get_tree(r, **attr)
XML Element tree export method
source code
 
put_tree(r, **attr)
XML Element tree import method
source code
 
get_struct(r, **attr)
Resource structure introspection method
source code
 
get_fields(r, **attr)
Resource structure introspection method (single table)
source code
 
get_options(r, **attr)
Field options introspection method (single table)
source code
 
unauthorised()
Action upon unauthorised request
source code
Class Variables
  INTERACTIVE_FORMATS = "html", "iframe", "popup", "dl"
  DEFAULT_REPRESENTATION = "html"
Properties

Inherited from object: __class__

Method Details

__init__(self, prefix=None, name=None, r=None, c=None, f=None, args=None, vars=None, extension=None, get_vars=None, post_vars=None, http=None)
(Constructor)

source code 

Constructor

Parameters:
  • prefix - the table name prefix
  • name - the table name
  • c - the controller prefix
  • f - the controller function
  • args - list of request arguments
  • vars - dict of request variables
  • extension - the format extension (representation)
  • get_vars - the URL query variables (overrides vars)
  • post_vars - the POST variables (overrides vars)
  • http - the HTTP method (GET, PUT, POST, or DELETE)
Overrides: object.__init__

Note: all parameters fall back to the attributes of the current web2py request object

set_handler(self, method, handler, http=None, representation=None, transform=False)

source code 

Set a method handler for this request

Parameters:
  • method - the method name
  • handler (handler(S3Request, **attr)) - the handler function
  • http - restrict to these HTTP methods, list|tuple
  • representation - register handler for non-transformable data formats
  • transform - register handler for transformable data formats (overrides representation)

get_handler(self, method, transform=False)

source code 

Get a method handler for this request

Parameters:
  • method - the method name
  • transform - get handler for transformable data format
Returns:
the method handler

get_widget_handler(self, method)

source code 

Get the widget handler for a method

Parameters:
  • r - the S3Request
  • method - the widget method

__call__(self, **attr)
(Call operator)

source code 

Execute this request

Parameters:
  • attr - Parameters for the method handler

get_tree(r, **attr)
Static Method

source code 

XML Element tree export method

Parameters:
  • r - the S3Request instance
  • attr - controller attributes

put_tree(r, **attr)
Static Method

source code 

XML Element tree import method

Parameters:
  • r - the S3Request method
  • attr - controller attributes

get_struct(r, **attr)
Static Method

source code 

Resource structure introspection method

Parameters:
  • r - the S3Request instance
  • attr - controller attributes

get_fields(r, **attr)
Static Method

source code 

Resource structure introspection method (single table)

Parameters:
  • r - the S3Request instance
  • attr - controller attributes

get_options(r, **attr)
Static Method

source code 

Field options introspection method (single table)

Parameters:
  • r - the S3Request instance
  • attr - controller attributes

factory(self, **args)

source code 

Generate a new request for the same resource

Parameters:
  • args - arguments for request constructor

__getattr__(self, key)
(Qualification operator)

source code 

Called upon S3Request.<key> - looks up the value for the <key> attribute. Falls back to current.request if the attribute is not defined in this S3Request.

Parameters:
  • key - the key to lookup

transformable(self, method=None)

source code 

Check the request for a transformable format

Parameters:
  • method - "import" for import methods, else None

actuate_link(self, component_id=None)

source code 

Determine whether to actuate a link or not

Parameters:
  • component_id - the component_id (if not self.component_id)

unauthorised()
Static Method

source code 

Action upon unauthorised request

error(self, status, message, tree=None, next=None)

source code 

Action upon error

Parameters:
  • status - HTTP status code
  • message - the error message
  • tree - the tree causing the error

url(self, id=None, component=None, component_id=None, target=None, method=None, representation=None, vars=None, host=None)

source code 

Returns the URL of this request, use parameters to override current requests attributes:

  • None to keep current attribute (default)
  • 0 or "" to set attribute to NONE
  • value to use explicit value
Parameters:
  • id - the master record ID
  • component - the component name
  • component_id - the component ID
  • target - the target record ID (choose automatically)
  • method - the URL method
  • representation - the representation for the URL
  • vars - the URL query variables
  • host - string to force absolute URL with host (True means http_host)

    Particular behavior:

    • changing the master record ID resets the component ID
    • removing the target record ID sets the method to None
    • removing the method sets the target record ID to None
    • [] as id will be replaced by the "[id]" wildcard

target(self)

source code 

Get the target table of the current request

Returns:
a tuple of (prefix, name, table, tablename) of the target resource of this request

To Do: update for link table support

stylesheet(self, method=None, skip_error=False)

source code 

Find the XSLT stylesheet for this request

Parameters:
  • method - "import" for data imports, else None
  • skip_error - do not raise an HTTP error status if the stylesheet cannot be found

read_body(self)

source code 

Read data from request body

customise_resource(self, tablename=None)

source code 

Invoke the customization callback for a resource.

@param tablename: the tablename of the resource; if called
                  without tablename it will invoke the callbacks
                  for the target resources of this request:
                    - master
                    - active component
                    - active link table
                  (in this order)

Resource customization functions can be defined like:

    def customise_resource_my_table(r, tablename):

        current.s3db.configure(tablename,
                               my_custom_setting = "example")
        return

    settings.customise_resource_my_table =                                         customise_resource_my_table

@note: the hook itself can call r.customise_resource in order
       to cascade customizations as necessary
@note: if a table is customised that is not currently loaded,
       then it will be loaded for this process


Class Variable Details

INTERACTIVE_FORMATS

Value:
"html", "iframe", "popup", "dl"

DEFAULT_REPRESENTATION

Value:
"html"