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

Class S3AddPersonWidget

source code

??-311 --+
         |
        S3AddPersonWidget


Widget for person_id (future also: human_resource_id) fields that
allows to either select an existing person (autocomplete), or to
create a new person record inline

Features:
- embedded fields configurable in deployment settings
- can use single name field (with on-submit name splitting),
  alternatively separate fields for first/middle/last names
- can check for possible duplicates during data entry
- fully encapsulated, works with regular validators (IS_ONE_OF)

=> Uses client-side script s3.ui.addperson.js (injected)

Instance Methods
 
__init__(self, controller=None, separate_name_fields=None, father_name=None, grandfather_name=None, year_of_birth=None, first_name_only=None, pe_label=False)
Constructor
source code
 
__call__(self, field, value, **attributes)
Widget builder
source code
 
extract(self, record_id, fields, details=False, hrm=False)
Extract the data for a record ID
source code
 
get_contact_data(self, pe_id)
Extract the contact data for a pe_id; extracts only the first value per contact method
source code
 
embedded_form(self, label, widget_id, formfields, values)
Construct the embedded form
source code
 
get_label(self, fieldname)
Get a label for an embedded field
source code
 
get_widget(self, fieldname, field)
Get a widget for an embedded field; only when the field needs a specific widget => otherwise return None here, so the form builder will render a standard INPUT
source code
 
inject_script(self, widget_id, options, i18n)
Inject the necessary JavaScript for the widget
source code
 
inject_i18n(self, labels)
Inject translations for screen messages rendered by the client-side script
source code
 
validate(self, value)
Validate main input value
source code
 
parse(self, value)
Parse the main input JSON when the form gets submitted
source code
 
get_names(self, data)
Get first, middle and last names from the input data
source code
 
validate_email(self, value, person_id=None)
Validate the email address; checks whether the email address is valid and unique
source code
 
create_person(self, data)
Create a new record from form data
source code
Static Methods
 
split_names(name)
Split a full name into first/middle/last
source code
Method Details

__init__(self, controller=None, separate_name_fields=None, father_name=None, grandfather_name=None, year_of_birth=None, first_name_only=None, pe_label=False)
(Constructor)

source code 

Constructor

Parameters:
  • controller - controller for autocomplete
  • separate_name_fields - use separate name fields, overrides deployment setting
  • father_name - expose father name field, overrides deployment setting
  • grandfather_name - expose grandfather name field, overrides deployment setting
  • year_of_birth - use just year-of-birth field instead of full date-of-birth, overrides deployment setting
  • first_name_only - treat single name field entirely as first name (=do not split into name parts), overrides auto-detection, otherwise default for right-to-left written languages
  • pe_label - expose ID label field

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

source code 

Widget builder

Parameters:
  • field - the Field
  • value - the current or default value
  • attributes - additional HTML attributes for the widget

extract(self, record_id, fields, details=False, hrm=False)

source code 

Extract the data for a record ID

Parameters:
  • record_id - the record ID
  • fields - the fields to extract, dict {propName: Field}
  • details - includes person details
  • hrm - record ID is a hrm_human_resource ID rather than person ID
Returns:
dict of {propName: value}

get_contact_data(self, pe_id)

source code 

Extract the contact data for a pe_id; extracts only the first value per contact method

Parameters:
  • pe_id - the pe_id
Returns:
a dict {fieldname: value}, where field names correspond to the contact method (field map)

embedded_form(self, label, widget_id, formfields, values)

source code 

Construct the embedded form

Parameters:
  • label - the label for the embedded form (= field label for the person_id)
  • widget_id - the widget ID (=element ID of the person_id field)
  • formfields - list of field names indicating which fields to render and in which order
  • values - dict with values to populate the embedded form
Returns:
a DIV containing the embedded form rows

get_label(self, fieldname)

source code 

Get a label for an embedded field

Parameters:
  • fieldname - the name of the embedded form field
Returns:
the label

get_widget(self, fieldname, field)

source code 

Get a widget for an embedded field; only when the field needs a specific widget => otherwise return None here, so the form builder will render a standard INPUT

Parameters:
  • fieldname - the name of the embedded form field
  • field - the Field corresponding to the form field
Returns:
the widget; or None if no specific widget is required

inject_script(self, widget_id, options, i18n)

source code 

Inject the necessary JavaScript for the widget

Parameters:
  • widget_id - the widget ID (=element ID of the person_id field)
  • options - JSON-serializable dict of widget options
  • i18n - translations of screen messages rendered by the client-side script, a dict {messageKey: translation}

inject_i18n(self, labels)

source code 

Inject translations for screen messages rendered by the client-side script

Parameters:
  • labels - dict of translations {messageKey: translation}

validate(self, value)

source code 

Validate main input value

Parameters:
  • value - the main input value (JSON)
Returns:
tuple (id, error), where "id" is the record ID of the selected or newly created record

parse(self, value)

source code 

Parse the main input JSON when the form gets submitted

Parameters:
  • value - the main input value (JSON)
Returns:
tuple (data, error), where data is a dict with the submitted data like: {fieldname: value, ...}

get_names(self, data)

source code 

Get first, middle and last names from the input data

Parameters:
  • data - the input data dict
Returns:
dict with the name parts found

split_names(name)
Static Method

source code 

Split a full name into first/middle/last

Parameters:
  • name - the full name
Returns:
tuple (first, middle, last)

validate_email(self, value, person_id=None)

source code 

Validate the email address; checks whether the email address is valid and unique

Parameters:
  • value - the email address
  • person_id - the person ID, if known
Returns:
tuple (value, error), where error is None if the email address is valid, otherwise contains the error message

create_person(self, data)

source code 

Create a new record from form data

@param data - the submitted data

Returns:
tuple (id, error), where "id" is the record ID of the newly created record