Package s3 :: Module s3model :: Class S3Model
[frames] | no frames]

Class S3Model

source code

object --+
         |
        S3Model

Base class for S3 models

Instance Methods
 
__init__(self, module=None)
Constructor
source code
 
__getattr__(self, name)
Model auto-loader
source code
 
__getitem__(self, key) source code
 
mandatory(self)
Mandatory objects defined by this model, regardless whether enabled or disabled
source code
 
model(self)
Defines all tables in this model, to be implemented by subclasses
source code
 
defaults(self)
Definitions of model globals (response.s3.*) if the model has been disabled in deployment settings, to be implemented by subclasses
source code

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

Class Methods
 
table(cls, tablename, default=None, db_only=False)
Helper function to load a table definition by its name
source code
 
get(cls, name, default=None)
Helper function to load a response.s3 variable from models
source code
 
load(cls, name)
Helper function to load a model by its name (=prefix)
source code
 
load_all_models(cls)
Helper function to load all models
source code
 
configure(cls, tablename, **attr)
Update the extra configuration of a table
source code
 
get_config(cls, tablename, key, default=None)
Reads a configuration attribute of a resource
source code
 
clear_config(cls, tablename, *keys)
Removes configuration attributes of a resource
source code
 
add_custom_callback(cls, tablename, hook, cb, method=None)
Generic method to append a custom onvalidation|onaccept callback to the originally configured callback chain, for use in customise_* in templates
source code
 
virtual_reference(cls, field)
Reverse-lookup of virtual references which are declared for the respective lookup-table as:
source code
 
onaccept(cls, table, record, method="create")
Helper to run the onvalidation routine for a record
source code
 
onvalidation(cls, table, record, method="create")
Helper to run the onvalidation routine for a record
source code
 
add_components(cls, master, **links)
Configure component links for a master table.
source code
 
add_dynamic_components(cls, tablename, exclude=None)
Helper function to look up and declare dynamic components for a table; called by get_components if dynamic_components is configured for the table
source code
 
get_component(cls, table, alias)
Get a component description for a component alias
source code
 
get_components(cls, table, names=None)
Finds components of a table
source code
 
parse_hook(cls, table, alias, hook=None)
Parse a component configuration, loading all necessary table models and applying defaults
source code
 
get_hooks(cls, table, names=None)
Find applicable component configurations (hooks) for a table
source code
 
has_components(cls, table)
Checks whether there are components defined for a table
source code
 
get_alias(cls, tablename, link)
Find a component alias from the link table alias.
source code
 
hierarchy_link(cls, tablename)
Get the alias of the component that represents the parent node in a hierarchy (for link-table based hierarchies)
source code
 
set_method(cls, prefix, name, component_name=None, method=None, action=None)
Adds a custom method for a resource or component
source code
 
get_method(cls, prefix, name, component_name=None, method=None)
Retrieves a custom method for a resource or component
source code
 
super_entity(cls, tablename, key, types, *fields, **args)
Define a super-entity table
source code
 
super_key(cls, supertable, default=None)
Get the name of the key for a super-entity
source code
 
super_link(cls, name, supertable, label=None, comment=None, represent=None, orderby=None, sort=True, filterby=None, filter_opts=None, not_filterby=None, not_filter_opts=None, instance_types=None, realms=None, updateable=False, groupby=None, script=None, widget=None, empty=True, default=DEFAULT, ondelete="CASCADE", readable=False, writable=False)
Get a foreign key field for a super-entity
source code
 
update_super(cls, table, record)
Updates the super-entity links of an instance record
source code
 
delete_super(cls, table, record)
Removes the super-entity links of an instance record
source code
 
get_super_keys(cls, table)
Get the super-keys in an instance table
source code
 
get_instance(cls, supertable, superid)
Get prefix, name and ID of an instance record
source code
Static Methods
 
define_table(tablename, *fields, **args)
Same as db.define_table except that it does not repeat a table definition if the table is already defined.
source code
 
get_aliased(table, alias)
Helper method to get a Table instance with alias; prevents re-instantiation of an already existing alias for the same table (which can otherwise lead to name collisions in PyDAL).
source code
 
resource(tablename, *args, **kwargs)
Wrapper for the S3Resource constructor to realize the global s3db.resource() method
source code
Class Variables
  LOCK = "s3_model_lock"
  LOAD = "s3_model_load"
  DELETED = "deleted"
Properties

Inherited from object: __class__

Method Details

__init__(self, module=None)
(Constructor)

source code 

Constructor

Overrides: object.__init__

__getattr__(self, name)
(Qualification operator)

source code 

Model auto-loader

__getitem__(self, key)
(Indexing operator)

source code 

mandatory(self)

source code 

Mandatory objects defined by this model, regardless whether enabled or disabled

model(self)

source code 

Defines all tables in this model, to be implemented by subclasses

defaults(self)

source code 

Definitions of model globals (response.s3.*) if the model has been disabled in deployment settings, to be implemented by subclasses

table(cls, tablename, default=None, db_only=False)
Class Method

source code 

Helper function to load a table definition by its name

get(cls, name, default=None)
Class Method

source code 

Helper function to load a response.s3 variable from models

load(cls, name)
Class Method

source code 

Helper function to load a model by its name (=prefix)

load_all_models(cls)
Class Method

source code 

Helper function to load all models

define_table(tablename, *fields, **args)
Static Method

source code 

Same as db.define_table except that it does not repeat a table definition if the table is already defined.

get_aliased(table, alias)
Static Method

source code 

Helper method to get a Table instance with alias; prevents re-instantiation of an already existing alias for the same table (which can otherwise lead to name collisions in PyDAL).

Parameters:
  • table - the original table
  • alias - the alias
Returns:
the aliased Table instance

resource(tablename, *args, **kwargs)
Static Method

source code 

Wrapper for the S3Resource constructor to realize the global s3db.resource() method

configure(cls, tablename, **attr)
Class Method

source code 

Update the extra configuration of a table

Parameters:
  • tablename - the name of the table
  • attr - dict of attributes to update

get_config(cls, tablename, key, default=None)
Class Method

source code 

Reads a configuration attribute of a resource

Parameters:
  • tablename - the name of the resource DB table
  • key - the key (name) of the attribute

clear_config(cls, tablename, *keys)
Class Method

source code 

Removes configuration attributes of a resource

Parameters:
  • table - the resource DB table
  • keys - keys of attributes to remove (maybe multiple)

add_custom_callback(cls, tablename, hook, cb, method=None)
Class Method

source code 

Generic method to append a custom onvalidation|onaccept
callback to the originally configured callback chain,
for use in customise_* in templates

@param tablename: the table name
@param hook: the main hook ("onvalidation"|"onaccept")
@param cb: the custom callback function
@param method: the sub-hook ("create"|"update"|None)

@example:
    # Add a create-onvalidation callback for the pr_person
    # table, while retaining any existing onvalidation:
    s3db.add_custom_callback("pr_person",
                             "onvalidation",
                             my_create_onvalidation,
                             method = "create",
                             )

virtual_reference(cls, field)
Class Method

source code 

Reverse-lookup of virtual references which are declared for
the respective lookup-table as:

    configure(tablename,
              referenced_by = [(tablename, fieldname), ...],
              )

& in the table with the fields(auth_user only current example) as:

    configure(tablename,
              references = {fieldname: tablename,
                            ...
                            },
              )

@param field: the Field

@returns: the name of the referenced table

onaccept(cls, table, record, method="create")
Class Method

source code 

Helper to run the onvalidation routine for a record

Parameters:
  • table - the Table
  • record - the FORM or the Row to validate
  • method - the method

onvalidation(cls, table, record, method="create")
Class Method

source code 

Helper to run the onvalidation routine for a record

Parameters:
  • table - the Table
  • record - the FORM or the Row to validate
  • method - the method

add_components(cls, master, **links)
Class Method

source code 

Configure component links for a master table.

Parameters:
  • master - the name of the master table
  • links - component link configurations

add_dynamic_components(cls, tablename, exclude=None)
Class Method

source code 

Helper function to look up and declare dynamic components for a table; called by get_components if dynamic_components is configured for the table

Parameters:
  • tablename - the table name
  • exclude - names to exclude (static components)

get_component(cls, table, alias)
Class Method

source code 

Get a component description for a component alias

Parameters:
  • table - the master table
  • alias - the component alias
Returns:
the component description (Storage)

get_components(cls, table, names=None)
Class Method

source code 

Finds components of a table

Parameters:
  • table - the table or table name
  • names - a list of components names to limit the search to, None for all available components
Returns:
the component descriptions (Storage {alias: description})

parse_hook(cls, table, alias, hook=None)
Class Method

source code 

Parse a component configuration, loading all necessary table models and applying defaults

Parameters:
  • table - the master table
  • alias - the component alias
  • hook - the component configuration (if already known)
Returns:
the component description (Storage {key: value})

get_hooks(cls, table, names=None)
Class Method

source code 

Find applicable component configurations (hooks) for a table

Parameters:
  • table - the master table (or table name)
  • names - component aliases to find (default: all configured components for the master table)
Returns:
tuple (table, {alias: hook, ...})

has_components(cls, table)
Class Method

source code 

Checks whether there are components defined for a table

Parameters:
  • table - the table or table name

get_alias(cls, tablename, link)
Class Method

source code 

Find a component alias from the link table alias.

Parameters:
  • tablename - the name of the master table
  • link - the alias of the link table

hierarchy_link(cls, tablename)
Class Method

source code 

Get the alias of the component that represents the parent node in a hierarchy (for link-table based hierarchies)

Parameters:
  • tablename - the table name
Returns:
the alias of the hierarchy parent component

set_method(cls, prefix, name, component_name=None, method=None, action=None)
Class Method

source code 

Adds a custom method for a resource or component

Parameters:
  • prefix - prefix of the resource name (=module name)
  • name - name of the resource (=without prefix)
  • component_name - name of the component
  • method - name of the method
  • action - function to invoke for this method

get_method(cls, prefix, name, component_name=None, method=None)
Class Method

source code 

Retrieves a custom method for a resource or component

Parameters:
  • prefix - prefix of the resource name (=module name)
  • name - name of the resource (=without prefix)
  • component_name - name of the component
  • method - name of the method

super_entity(cls, tablename, key, types, *fields, **args)
Class Method

source code 

Define a super-entity table

Parameters:
  • tablename - the tablename
  • key - name of the primary key
  • types - a dictionary of instance types
  • fields - any shared fields
  • args - table arguments (e.g. migrate)

super_key(cls, supertable, default=None)
Class Method

source code 

Get the name of the key for a super-entity

Parameters:
  • supertable - the super-entity table

super_link(cls, name, supertable, label=None, comment=None, represent=None, orderby=None, sort=True, filterby=None, filter_opts=None, not_filterby=None, not_filter_opts=None, instance_types=None, realms=None, updateable=False, groupby=None, script=None, widget=None, empty=True, default=DEFAULT, ondelete="CASCADE", readable=False, writable=False)
Class Method

source code 

Get a foreign key field for a super-entity

Parameters:
  • supertable - the super-entity table
  • label - label for the field
  • comment - comment for the field
  • readable - set the field readable
  • represent - set a representation function for the field

update_super(cls, table, record)
Class Method

source code 

Updates the super-entity links of an instance record

Parameters:
  • table - the instance table
  • record - the instance record

delete_super(cls, table, record)
Class Method

source code 

Removes the super-entity links of an instance record

Parameters:
  • table - the instance table
  • record - the instance record
Returns:
True if successful, otherwise False (caller must roll back the transaction if False is returned!)

get_super_keys(cls, table)
Class Method

source code 

Get the super-keys in an instance table

Parameters:
  • table - the instance table
Returns:
list of field names

get_instance(cls, supertable, superid)
Class Method

source code 

Get prefix, name and ID of an instance record

Parameters:
  • supertable - the super-entity table
  • superid - the super-entity record ID
Returns:
a tuple (prefix, name, ID) of the instance record (if it exists)

Class Variable Details

LOCK

Value:
"s3_model_lock"

LOAD

Value:
"s3_model_load"

DELETED

Value:
"deleted"