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

Class S3AgeWidget

source code

??-304 --+
         |
        S3AgeWidget


Widget to accept and represent date of birth as age in years,
mapping the age to a pseudo date-of-birth internally so that
it progresses over time; contains both widget and representation
method

@example:
    s3_date("date_of_birth",
            label = T("Age"),
            widget = S3AgeWidget.widget,
            represent = lambda v: S3AgeWidget.date_as_age(v)                                           if v else current.messages["NONE"],
            ...
            )

Class Methods
 
widget(cls, field, value, **attributes)
The widget method, renders a simple integer-input
source code
Static Methods
 
date_as_age(value, row=None)
Convert a date value into age in years, can be used as representation method
source code
 
age_as_date(value, error_message="invalid age")
Convert age in years into an approximate date of birth, acts as inner validator of the widget
source code
Method Details

widget(cls, field, value, **attributes)
Class Method

source code 

The widget method, renders a simple integer-input

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

date_as_age(value, row=None)
Static Method

source code 

Convert a date value into age in years, can be used as representation method

Parameters:
  • value - the date
Returns:
the age in years (integer)

age_as_date(value, error_message="invalid age")
Static Method

source code 

Convert age in years into an approximate date of birth, acts as inner validator of the widget

Parameters:
  • value - age value
  • error_message - error message (override)
Returns:
tuple (date, error)