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

Class S3Represent

source code

object --+
         |
        S3Represent

Scalable universal field representation for option fields and foreign keys. Can be subclassed and tailored to the particular model where necessary.

Instance Methods

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

    Configuration (in the model)
 
__init__(self, lookup=None, key=None, fields=None, labels=None, options=None, translate=False, linkto=None, show_link=False, multiple=False, hierarchy=False, default=None, none=None, field_sep=" ")
Constructor
source code
    API (to apply the method)
 
__call__(self, value, row=None, show_link=True)
Represent a single value (standard entry point).
source code
 
multiple(self, values, rows=None, list_type=True, show_link=True)
Represent multiple values as a comma-separated list.
source code
 
bulk(self, values, rows=None, list_type=True, show_link=True)
Represent multiple values as dict {value: representation}
source code
 
render_list(self, value, labels, show_link=True)
Helper method to render list-type representations from bulk()-results.
source code
    Prototypes (to adapt in subclasses)
 
lookup_rows(self, key, values, fields=None)
Lookup all rows referenced by values.
source code
 
represent_row(self, row, prefix=None)
Represent the referenced row.
source code
 
link(self, k, v, row=None)
Represent a (key, value) as hypertext link.
source code
Properties

Inherited from object: __class__

Method Details

__init__(self, lookup=None, key=None, fields=None, labels=None, options=None, translate=False, linkto=None, show_link=False, multiple=False, hierarchy=False, default=None, none=None, field_sep=" ")
(Constructor)

source code 

Constructor

Parameters:
  • lookup - the name of the lookup table
  • key - the field name of the primary key of the lookup table, a field name
  • fields - the fields to extract from the lookup table, a list of field names
  • labels - string template or callable to represent rows from the lookup table, callables must return a string
  • options - dictionary of options to lookup the representation of a value, overrides lookup and key
  • multiple - web2py list-type (all values will be lists)
  • hierarchy - render a hierarchical representation, either True or a string template like "%s > %s"
  • translate - translate all representations (using T)
  • linkto - a URL (as string) to link representations to, with "[id]" as placeholder for the key
  • show_link - whether to add a URL to representations
  • default - default representation for unknown options
  • none - representation for empty fields (None or empty list)
  • field_sep - separator to use to join fields
Overrides: object.__init__

lookup_rows(self, key, values, fields=None)

source code 

Lookup all rows referenced by values. (in foreign key representations)

Parameters:
  • key - the key Field
  • values - the values
  • fields - the fields to retrieve

represent_row(self, row, prefix=None)

source code 

Represent the referenced row. (in foreign key representations)

Parameters:
  • row - the row
  • prefix - prefix for hierarchical representation
Returns:
the representation of the Row, or None if there is an error in the Row

link(self, k, v, row=None)

source code 

Represent a (key, value) as hypertext link.

  • Typically, k is a foreign key value, and v the representation of the referenced record, and the link shall open a read view of the referenced record.
  • In the base class, the linkto-parameter expects a URL (as string) with "[id]" as placeholder for the key.
Parameters:
  • k - the key
  • v - the representation of the key
  • row - the row with this key (unused in the base class)

__call__(self, value, row=None, show_link=True)
(Call operator)

source code 

Represent a single value (standard entry point).

Parameters:
  • value - the value
  • row - the referenced row (if value is a foreign key)
  • show_link - render the representation as link

multiple(self, values, rows=None, list_type=True, show_link=True)

source code 

Represent multiple values as a comma-separated list.

Parameters:
  • values - list of values
  • rows - the referenced rows (if values are foreign keys)
  • show_link - render each representation as link

bulk(self, values, rows=None, list_type=True, show_link=True)

source code 

Represent multiple values as dict {value: representation}

Parameters:
  • values - list of values
  • rows - the rows
  • show_link - render each representation as link
Returns:
a dict {value: representation}

Note: for list-types, the dict keys will be the individual values within all lists - and not the lists (simply because lists can not be dict keys). Thus, the caller would still have to construct the final string/HTML.

render_list(self, value, labels, show_link=True)

source code 

Helper method to render list-type representations from bulk()-results.

Parameters:
  • value - the list
  • labels - the labels as returned from bulk()
  • show_link - render references as links, should be the same as used with bulk()