Package s3 :: Module s3widgets :: Class S3Selector
[frames] | no frames]

Class S3Selector

source code

??-278 --+
         |
        S3Selector

Base class for JSON-based complex selectors (e.g. S3LocationSelector), used to detect this widget class during form processing, and to apply a common API.

Subclasses must implement:

Subclasses should use:

Instance Methods
 
__call__(self, field, value, **attributes)
Widget renderer.
source code
 
extract(self, record_id, values=None)
Extract the record from the database and update values.
source code
 
represent(self, value)
Representation method for new or updated value dicts.
source code
 
validate(self, value, requires=None)
Parse and validate the input value, but don't create or update any records.
source code
 
postprocess(self, value)
Post-process to create or update records.
source code
 
inputfield(self, field, values, classes, **attributes)
Generate the (hidden) input field.
source code
 
serialize(self, values)
Serialize the values (as JSON string).
source code
 
parse(self, value)
Parse the form value into a dict.
source code
Method Details

__call__(self, field, value, **attributes)
(Call operator)

source code 

Widget renderer.

To be implemented in subclass.

Parameters:
  • field - the Field
  • value - the current value(s)
  • attr - additional HTML attributes for the widget
Returns:
the widget HTML

extract(self, record_id, values=None)

source code 

Extract the record from the database and update values.

To be implemented in subclass.

Parameters:
  • record_id - the record ID
  • values - the values dict
Returns:
the (updated) values dict

represent(self, value)

source code 

Representation method for new or updated value dicts.

IMPORTANT: This method *must not* change DB status because it
           is called from inline forms before the the row is
           committed to the DB, so any DB status change would
           be invalid at this point.

To be implemented in subclass.

@param values: the values dict

@return: string representation for the values dict

validate(self, value, requires=None)

source code 

Parse and validate the input value, but don't create or update any records. This will be called by S3CRUD.validate to validate inline-form values.

To be implemented in subclass.

Parameters:
  • value - the value from the form
  • requires - the field validator
Returns:
tuple (values, error) with values being the parsed value dict, and error any validation errors

postprocess(self, value)

source code 

Post-process to create or update records. Called during POST before validation of the outer form.

To be implemented in subclass.

Parameters:
  • value - the value from the form (as JSON)
Returns:
tuple (record_id, error)

inputfield(self, field, values, classes, **attributes)

source code 

Generate the (hidden) input field. Should be used in __call__.

Parameters:
  • field - the Field
  • values - the parsed value (as dict)
  • classes - standard HTML classes
  • attributes - the widget attributes as passed in to the widget
Returns:
the INPUT field

serialize(self, values)

source code 

Serialize the values (as JSON string). Called from inputfield().

Parameters:
  • values - the values (as dict)
Returns:
the serialized values

parse(self, value)

source code 

Parse the form value into a dict. The value would be a record id if coming from the database, or a JSON string when coming from a form. Should be called from validate(), doesn't need to be re-implemented in subclass.

Parameters:
  • value - the value
Returns:
the parsed data as dict