CollectionModelResource

class flask_restful_dbbase.resources.CollectionModelResource[source]

Bases: DBBaseResource

CollectionModelResource Class

This model class implements the base class.

This class supports only gets to return collections of records.

Like the ModelResource class there is a provision for a process_get_input function.

The usual filtering is available for gathering records if a variable is a specific value. Most of the time, this will be all that is necessary.

However, there is a means to select records by a comparison operator.

Use a format as follows:

query_string: {

var1: [operator, comparison_value]

}

The list of operators for single comparison value is:

[“eq”, “ne”, “gt”, “ge”, “lt”, “le”]

In addition, if comparison is made such as selecting where var1 > var2, use {var1: [“gt”, var:var2]} to signal this is another variable.

To gather records that are found in a list use var1[]: [val1, val2, …].

Or, for more flexibility use:

query_string: {

var1: [operator, [val1, val2, …]]

}

The supported list of operators are

[“like”, “ilike”, “notlike”, “notilike”]

To control record set sizes, a variable page_config is a dict of page or record variables.

Bear in mind tha all variables entering can be either camel or snake based.

Page_config variables:

“orderBy”: [“id”, “statusId”],

Can be a single value or a list To sort in descending order use the format -var1

“pageSize”: “50”,

The maximum page size can be limited by the class variable max_page_size

“offset”: 30, The number of records to skip

“limit”: “100”,

limits the size of the record set

“serialFields”: [“id”, “statusId”],

can specify specific columns to be returned fallback: serial fields can be specified by resource or dbbase model

“debug”: “False”,

covered below

if debug is true, the recordset is not returned. Instead, data returned consists of variables used, the default variable amounts, and the sqlalchemy query that would be executed.

“class_defaults”: {

“model_name”: self.model_name, “process_get_input”: get_input_doc, “max_page_size”: self.max_page_size, “order_by”: None, “op_codes”: self.OP_CODES1 + self.OP_CODES2,

}, “original_data”: orig_data, “converted_data”: query_data, “page_configs”: configs, “query”: str(query)

Methods

as_view(name, *class_args, **class_kwargs)

Convert the class into a view function that can be registered for a route.

create_url()

Url can come from: * url_name resource variable

dispatch_request(*args, **kwargs)

The actual view function behavior.

format_key(key, key_type)

This function returns the portion of the URL that embodies the key.

get()

get_key_names([formatted])

This function returns column names marked as primary_key.

get_meta([method])

This function returns the settings for the resource.

get_obj_params()

This is a convenience function for getting documentation parameters from the model class.

get_urls()

This function returns something similar to

is_collection()

This function returns True if identified as a collection resource.

screen_data(data, obj_params[, ...])

Assumes data is deserialized

Attributes

OP_CODES1

OP_CODES2

after_commit

before_commit

decorators

A list of decorators to apply, in order, to the generated view function.

default_sort

fields

init_every_request

Create a new instance of this view class for every request by default.

max_page_size

meta_doc

method_decorators

methods

The methods this view is registered for.

model_class

model_name

The string version of the Model class name.

order_by

process_get_input

provide_automatic_options

Control whether the OPTIONS method is handled automatically.

representations

requires_parameter

serial_field_relations

serial_fields

url_name

url_prefix

use_date_conversions

use_date_conversions can be used if the database, such as SQlite3 does not support the acceptance of string-based dates.

model_name = None

The string version of the Model class name. This is set upon initialization.

methods = {'GET'}

The methods this view is registered for. Uses the same default (["GET", "HEAD", "OPTIONS"]) as route and add_url_rule by default.