Package s3 :: Module s3forms :: Class S3SQLInlineComponent
[frames] | no frames]

Class S3SQLInlineComponent

source code

      object --+        
               |        
S3SQLFormElement --+    
                   |    
        S3SQLSubForm --+
                       |
                      S3SQLInlineComponent


Form element for an inline-component-form

This form element allows CRUD of multi-record-components within
the main record form. It renders a single hidden text field with a
JSON representation of the component records, and a widget which
facilitates client-side manipulation of this JSON.
This widget is a row of fields per component record.

The widget uses the s3.ui.inline_component.js script for client-side
manipulation of the JSON data. Changes made by the script will be
validated through Ajax-calls to the CRUD.validate() method.
During accept(), the component gets updated according to the JSON
returned.

@ToDo: Support filtering of field options
       Usecase is inline project_organisation for IFRC
       PartnerNS needs to be filtered differently from Partners/Donors,
       so can't just set a global requires for the field in the controller
       - needs to be inside the widget.
       See private/templates/IFRC/config.py

Instance Methods
 
resolve(self, resource)
Method to resolve this form element against the calling resource.
source code
 
extract(self, resource, record_id)
Initialize this form element for a particular record.
source code
 
parse(self, value)
Validator method, converts the JSON returned from the input field into a Python object.
source code
 
__call__(self, field, value, **attributes)
Widget method for this form element.
source code
 
represent(self, value)
Read-only representation of this sub-form
source code
 
accept(self, form, master_id=None, format=None)
Post-processes this form element against the POST data of the request, and create/update/delete any related records.
source code

Inherited from S3SQLFormElement: __init__

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

Class Variables
  prefix = "sub"
Properties

Inherited from object: __class__

Method Details

resolve(self, resource)

source code 

Method to resolve this form element against the calling resource.

Parameters:
  • resource - the resource
Returns:
a tuple (self, None, Field instance)
Overrides: S3SQLFormElement.resolve

extract(self, resource, record_id)

source code 

Initialize this form element for a particular record. Retrieves the component data for this record from the database and converts them into a JSON string to populate the input field with.

Parameters:
  • resource - the resource the record belongs to
  • record_id - the record ID
Returns:
the JSON for the input field.
Overrides: S3SQLSubForm.extract

parse(self, value)

source code 

Validator method, converts the JSON returned from the input field into a Python object.

Parameters:
  • value - the JSON from the input field.
Returns:
tuple of (value, error), where value is the converted JSON, and error the error message if the decoding fails, otherwise None
Overrides: S3SQLSubForm.parse

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

source code 

Widget method for this form element. Renders a table with read-rows for existing entries, a variable edit-row to update existing entries, and an add-row to add new entries. This widget uses s3.inline_component.js to facilitate manipulation of the entries.

Parameters:
  • field - the Field for this form element
  • value - the current value for this field
  • attributes - keyword attributes for this widget
Returns:
the widget for this form element as HTML helper
Overrides: S3SQLSubForm.__call__

represent(self, value)

source code 

Read-only representation of this sub-form

Parameters:
  • value - the value returned from extract()
Returns:
the read-only representation of this element as string or HTML helper
Overrides: S3SQLSubForm.represent

accept(self, form, master_id=None, format=None)

source code 

Post-processes this form element against the POST data of the request, and create/update/delete any related records.

Parameters:
  • form - the form
  • master_id - the ID of the master record in the form
  • format - the data format extension (for audit)
Returns:
True on success, False on error
Overrides: S3SQLSubForm.accept

Class Variable Details

prefix

Value:
"sub"