Package s3 :: Module s3fields
[frames] | no frames]

Module s3fields

source code

S3 Extensions for gluon.dal.Field, reusable fields


Requires: gluon

Copyright: 2009-2019 (c) Sahana Software Foundation

License: MIT

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Classes
  FieldS3
S3 extensions of the gluon.sql.Field class
  S3ReusableField
DRY Helper for reusable fields:
  S3Represent
Scalable universal field representation for option fields and foreign keys.
  S3RepresentLazy
Lazy Representation of a field value, utilizes the bulk-feature of S3Represent-style representation methods
  S3MetaFields
Class to standardize meta-fields
Functions
 
s3_fieldmethod(name, f, represent=None, search_field=None)
Helper to attach a representation method to a Field.Method.
source code
 
s3_meta_fields()
Shortcut commonly used in table definitions: *s3_meta_fields()
source code
 
s3_all_meta_field_names()
Shortcut commonly used to include/exclude meta fields
source code
 
s3_role_required()
Role Required to access a resource...
source code
 
s3_roles_permitted(name="roles_permitted", **attr)
List of Roles Permitted to access a resource...
source code
 
s3_comments(name="comments", **attr)
Return a standard Comments field
source code
 
s3_currency(name="currency", **attr)
Return a standard Currency field
source code
 
s3_language(name="language", **attr)
Return a standard Language field
source code
 
s3_date(name="date", **attr)
Return a standard date-field
source code
 
s3_datetime(name="date", **attr)
Return a standard datetime field
source code
Variables
  s3uuid = SQLCustomType(type= "string", native= "VARCHAR(128)",...
  auth_group_represent = S3Represent(lookup= "auth_group", field...
  ALL_META_FIELD_NAMES = "uuid", "mci", "deleted", "deleted_fk",...
Function Details

s3_fieldmethod(name, f, represent=None, search_field=None)

source code 

Helper to attach a representation method to a Field.Method.

Parameters:
  • name - the field name
  • f - the field method
  • represent - the representation function
  • search_field - the field to use for searches
    • only used by datatable_filter currently
    • can only be a single field in the same table currently

s3_meta_fields()

source code 

Shortcut commonly used in table definitions: *s3_meta_fields()

Returns:
tuple of Field instances

s3_all_meta_field_names()

source code 

Shortcut commonly used to include/exclude meta fields

Returns:
tuple of field names

s3_role_required()

source code 

Role Required to access a resource
- used by GIS for map layer permissions management

s3_roles_permitted(name="roles_permitted", **attr)

source code 

List of Roles Permitted to access a resource
- used by CMS

s3_comments(name="comments", **attr)

source code 

Return a standard Comments field

s3_currency(name="currency", **attr)

source code 

Return a standard Currency field

To Do: Move to a Finance module?

s3_language(name="language", **attr)

source code 

Return a standard Language field

s3_date(name="date", **attr)

source code 

Return a standard date-field

Parameters:
  • name - the field name
  • default - the field default, can be specified as "now" for current date, or as Python date
  • past - number of selectable past months
  • future - number of selectable future months
  • widget - the form widget for the field, can be specified as "date" for S3DateWidget, "calendar" for S3CalendarWidget, or as a web2py FormWidget, defaults to "calendar"
  • calendar - the calendar to use for this widget, defaults to current.calendar
  • start_field - CSS selector for the start field for interval selection
  • default_interval - the default interval
  • default_explicit - whether the user must click the field to set the default, or whether it will automatically be set when the value for start_field is set
  • set_min - CSS selector for another date/time widget to dynamically set the minimum selectable date/time to the value selected in this widget
  • set_max - CSS selector for another date/time widget to dynamically set the maximum selectable date/time to the value selected in this widget
Notes:
  • other S3ReusableField keywords are also supported (in addition to the above)
  • calendar-option requires widget="calendar" (default), otherwise Gregorian calendar is enforced for the field
  • set_min/set_max only supported for widget="calendar" (default)
  • interval options currently not supported by S3CalendarWidget, only available with widget="date"
  • start_field and default_interval should be given together
  • sets a default field label "Date" => use label-keyword to override if necessary
  • sets a default validator IS_UTC_DATE => use requires-keyword to override if necessary
  • sets a default representation S3DateTime.date_represent => use represent-keyword to override if necessary

To Do: Different default field name in case we need to start supporting Oracle, where 'date' is a reserved word

s3_datetime(name="date", **attr)

source code 

Return a standard datetime field

Parameters:
  • name - the field name
  • default - the field default, can be specified as "now" for current date/time, or as Python date
  • past - number of selectable past hours
  • future - number of selectable future hours
  • widget - form widget option, can be specified as "date" for date-only, or "datetime" for date+time (default), or as a web2py FormWidget
  • calendar - the calendar to use for this field, defaults to current.calendar
  • set_min - CSS selector for another date/time widget to dynamically set the minimum selectable date/time to the value selected in this widget
  • set_max - CSS selector for another date/time widget to dynamically set the maximum selectable date/time to the value selected in this widget
Notes:
  • other S3ReusableField keywords are also supported (in addition to the above)
  • sets a default field label "Date" => use label-keyword to override if necessary
  • sets a default validator IS_UTC_DATE/IS_UTC_DATETIME => use requires-keyword to override if necessary
  • sets a default representation S3DateTime.date_represent or S3DateTime.datetime_represent respectively => use the represent-keyword to override if necessary

To Do: Different default field name in case we need to start supporting Oracle, where 'date' is a reserved word


Variables Details

s3uuid

Value:
SQLCustomType(type= "string", native= "VARCHAR(128)", encoder= lambda \
x: "%s" %(uuid4().urn if x== "" else str(x.encode("utf-8"))), decoder=\
 lambda x: x)

auth_group_represent

Value:
S3Represent(lookup= "auth_group", fields= ["role"])

ALL_META_FIELD_NAMES

Value:
"uuid", "mci", "deleted", "deleted_fk", "deleted_rb", "created_on", "c\
reated_by", "modified_on", "modified_by", "approved_by", "owned_by_use\
r", "owned_by_group", "realm_entity",