Package s3 :: Module s3validators :: Class IS_ONE_OF_EMPTY
[frames] | no frames]

Class IS_ONE_OF_EMPTY

source code

gluon.validators.Validator --+
                             |
                            IS_ONE_OF_EMPTY


Filtered version of IS_IN_DB():

validates a given value as key of another table, filtered by the
'filterby' field for one of the 'filter_opts' options
(=a selective IS_IN_DB())

NB Filtering isn't active in GQL.

For the dropdown representation:

    'label' can be a string template for the record, or a set of field
    names of the fields to be used as option labels, or a function or
    lambda to create an option label from the respective record (which
    has to return a string, of course). The function will take the
    record as an argument.

    No 'options' method as designed to be called next to an
    Autocomplete field so don't download a large dropdown
    unnecessarily.

Instance Methods
 
__init__(self, dbset, field, label=None, filterby=None, filter_opts=None, not_filterby=None, not_filter_opts=None, realms=None, updateable=False, instance_types=None, error_message="invalid value!", orderby=None, groupby=None, left=None, multiple=False, zero="", sort=True, _and=None)
Validator for foreign keys.
source code
 
set_self_id(self, record_id) source code
 
set_filter(self, filterby=None, filter_opts=None, not_filterby=None, not_filter_opts=None)
This can be called from prep to apply a filter based on data in the record or the primary resource id.
source code
 
build_set(self)
Look up selectable options from the database
source code
 
query(self, table, fields=None, dd=None)
Construct the query to lookup the options (separated from build_set so the query can be extracted and used in other lookups, e.g.
source code
 
__call__(self, value) source code
Class Methods
 
accessible_query(cls, method, table, instance_types=None)
Returns an accessible query (and left joins, if necessary) for records in table the user is permitted to access with method
source code
Method Details

__init__(self, dbset, field, label=None, filterby=None, filter_opts=None, not_filterby=None, not_filter_opts=None, realms=None, updateable=False, instance_types=None, error_message="invalid value!", orderby=None, groupby=None, left=None, multiple=False, zero="", sort=True, _and=None)
(Constructor)

source code 

Validator for foreign keys.

Parameters:
  • dbset - a Set of records like db(query), or db itself
  • field - the field in the referenced table
  • label - lookup method for the label corresponding a value, alternatively a string template to be filled with values from the record
  • filterby - a field in the referenced table to filter by
  • filter_opts - values for the filterby field which indicate records to include
  • not_filterby - a field in the referenced table to filter by
  • not_filter_opts - values for not_filterby field which indicate records to exclude
  • realms - only include records belonging to the listed realms (if None, all readable records will be included)
  • updateable - only include records in the referenced table which can be updated by the user (if False, all readable records will be included)
  • instance_types - if the referenced table is a super-entity, then only include these instance types (this parameter is required for super entity lookups!)
  • error_message - the error message to return for failed validation
  • orderby - orderby for the options
  • groupby - groupby for the options
  • left - additional left joins required for the options lookup (super-entity instance left joins will be included automatically)
  • multiple - allow multiple values (for list:reference types)
  • zero - add this as label for the None-option (allow selection of "None")
  • sort - sort options alphabetically by their label
  • _and - internal use

set_self_id(self, record_id)

source code 

set_filter(self, filterby=None, filter_opts=None, not_filterby=None, not_filter_opts=None)

source code 

This can be called from prep to apply a filter based on data in the record or the primary resource id.

build_set(self)

source code 

Look up selectable options from the database

query(self, table, fields=None, dd=None)

source code 

Construct the query to lookup the options (separated from build_set so the query can be extracted and used in other lookups, e.g. filter options).

Parameters:
  • table - the lookup table
  • fields - fields (updatable list)
  • dd - additional query options (updatable dict)

accessible_query(cls, method, table, instance_types=None)
Class Method

source code 

Returns an accessible query (and left joins, if necessary) for records in table the user is permitted to access with method

Parameters:
  • method - the method (e.g. "read" or "update")
  • table - the table
  • instance_types - list of instance tablenames, if table is a super-entity (required in this case!)
Returns:
tuple (query, left) where query is the query and left joins is the list of left joins required for the query

Note: for higher security policies and super-entities with many instance types this can give a very complex query. Try to always limit the instance types to what is really needed

__call__(self, value)
(Call operator)

source code