tornado_restless.handler – BaseHandler¶
- class tornado_restless.handler.BaseHandler(application, request, **kwargs)[source]¶
Basic Blueprint for a sqlalchemy model
Subclass of tornado.web.RequestHandler that handles web requests.
Overwrite get() / post() / put() / patch() / delete() if you want complete customize handling of the methods. Note that the default implementation of this function check for the allowness and then call depending on the instance_id parameter the associated _single / _many method, so you probably want to call super()
If you just want to customize the handling of the methods overwrite method_single or method_many.
If you want completly disable a method overwrite the SUPPORTED_METHODS constant
- initialize(model, manager, methods: set, preprocessor: dict, postprocessor: dict, allow_patch_many: bool, allow_method_override: bool, validation_exceptions, exclude_queries: bool, exclude_hybrids: bool, include_columns: list, exclude_columns: list, results_per_page: int, max_results_per_page: int)[source]¶
Init of the handler, derives arguments from api create_api_blueprint
Parameters: - model – The sqlalchemy model
- manager – The tornado_restless Api Manager
- methods – Allowed methods for this model
- preprocessor – A dictionary of preprocessor functions
- postprocessor – A dictionary of postprocessor functions
- allow_patch_many – Allow PATCH with multiple datasets
- allow_method_override – Support X-HTTP-Method-Override Header
- validation_exceptions –
- exclude_queries – Don’t execude dynamic queries (like from associations or lazy relations)
- exclude_hybrids – When exclude_queries is True and exclude_hybrids is False, hybrids are still included.
- include_columns – Whitelist of columns to be included
- exclude_columns – Blacklist of columns to be excluded
- results_per_page – The default value of how many results are returned per request
- max_results_per_page – The hard upper limit of resutest per page
Reqheader X-HTTP-Method-Override: If allow_method_override is True, this header overwrites the request method
- get(instance_id: str=None)[source]¶
GET request
Parameters: instance_id (comma seperated string list) – query argument of request Statuscode 405: GET disallowed
- get_single(instance_id: list) → dict[source]¶
Get one instance
Parameters: instance_id (list of primary keys) – query argument of request
- get_many() → dict[source]¶
Get all instances
Note that it is possible to provide offset and page as argument then it will return instances of the nth page and skip offset items
Statuscode 400: if results_per_page > max_results_per_page or offset < 0 Query results_per_page: Overwrite the returned results_per_page Query offset: Skip offset instances Query page: Return nth page Query limit: limit the count of modified instances Query single: If true sqlalchemy will raise an error if zero or more than one instances would be deleted
- post(instance_id: str=None)[source]¶
POST (new input) request
Parameters: instance_id – (ignored) Statuscode 204: instance successfull created Statuscode 404: Error Statuscode 405: POST disallowed
- patch(instance_id: str=None)[source]¶
PATCH (update instance) request
Parameters: instance_id (comma seperated string list) – query argument of request Statuscode 403: PATCH MANY disallowed Statuscode 405: PATCH disallowed
- patch_single(instance_id: list) → dict[source]¶
Patch one instance
Parameters: instance_id (list of primary keys) – query argument of request Statuscode 201: instance successfull modified Statuscode 404: Error
- patch_many() → dict[source]¶
Patch many instances
Statuscode 201: instances successfull modified Query limit: limit the count of modified instances Query single: If true sqlalchemy will raise an error if zero or more than one instances would be modified
- put(instance_id: str=None)[source]¶
PUT (update instance) request
Parameters: instance_id (comma seperated string list) – query argument of request Statuscode 403: PUT MANY disallowed Statuscode 404: Error Statuscode 405: PUT disallowed
- delete(instance_id: str=None)[source]¶
DELETE (delete instance) request
Parameters: instance_id (comma seperated string list) – query argument of request Statuscode 403: DELETE MANY disallowed Statuscode 405: DELETE disallowed
- delete_single(instance_id: list) → dict[source]¶
Get one instance
Parameters: instance_id (list of primary keys) – query argument of request Statuscode 204: instance successfull removed