Package orm2 :: Module datatypes :: Class property_group
[hide private]
[frames] | no frames]

Class property_group

source code

object --+        
         |        
  property --+    
             |    
      datatype --+
                 |
                property_group

This datatype will manage several columns of the same datatype that follow a naming convention. It is maily indended for database tables that store several versions of a string in several columns, as for example for applications where you have more than one language.

Example:
  CREATE TABLE item_category
  (
     id SERIAL,
     name_en TEXT,
     name_de TEXT,

     PRIMARY KEY(id)
  )
And in Python:
  class item_category:
      id = serial()
      name = datatype_group(Unicode, ('en', 'de',), 'en')
The datatype_group instance will add one dbproperty to the dbclass for each postfix you supply. These are not accessible directly, but the datatype_group dbproperty will behave like a Python dictionary:
  lang = 'de'
  category_name = item_category.name[lang]
The naming convention for the database column goes <attribute name>_<postfix>. If you want to use your own column names, you may pass a dictionary as the postfixes parameter like:
  { 'p1': sql.column(name1), 'p2': sql.column(name2) }
In this case the implementation will accept any datatype for the postfixes.

Nested Classes [hide private]
  result

Instance Methods [hide private]
  __init__(self, inside_datatype, postfixes, default_postfix=None, title=None, validators=(), has_default=False)
The rest of the params just like datatype.
  __init_dbclass__(self, dbclass, attribute_name)
This methods gets called by dbobject's metaclass.
  inside_dbproperties(self)
Return a dict as { postfix: <datatype instance> }
  __get__(self, dbobj, owner="")
See the Python Language Reference, chapter 3.3.2.2 for details on how this works.
  __set__(self, dbobj, value)
Set the attribute managed by this datatype class on instance to value.
  __set_from_result__(self, ds, dbobj, value)
  isset(self, dbobj)
  sql_literal(self, dbobj)
Return an SQL literal representing the data managed by this property in dbobj.
  __select_this_column__(self)
Indicate whether this column shall be included in SELECT statements.
  __select_after_insert__(self, dbobj)
Indicate whether this column needs to be SELECTed after the dbobj has been inserted to pick up information supplied by backend as by SQL default values and auto increment columns.

Inherited from datatype: __convert__, __delete__, __setattr__, add_widget, check_dbobj, data_attribute_name, widget_specs

Inherited from property: __getattribute__, __new__

Inherited from object: __delattr__, __hash__, __reduce__, __reduce_ex__, __repr__, __str__


Class Variables [hide private]

Inherited from datatype: python_class, sql_literal_class

Inherited from property: fdel, fget, fset


Properties [hide private]

Inherited from object: __class__


Method Details [hide private]

__init__(self, inside_datatype, postfixes, default_postfix=None, title=None, validators=(), has_default=False)
(Constructor)

source code 
The rest of the params just like datatype.
Parameters:
  • inside_datatype - This is the datatype <b>class</b> for the managed attributes.
  • postfixes - This may either be a tuple of strings, which will be used in the column names as described above or a dictionary mapping arbitrary keys to column names.
Overrides: datatype.__init__

__init_dbclass__(self, dbclass, attribute_name)

source code 
This methods gets called by dbobject's metaclass. It supplies the db property with info about the class it belongs to and its attribute name.
Overrides: datatype.__init_dbclass__
(inherited documentation)

inside_dbproperties(self)

source code 
Return a dict as { postfix: <datatype instance> }

__get__(self, dbobj, owner="")

source code 
See the Python Language Reference, chapter 3.3.2.2 for details on how this works. Be sure to be in a relaxed, ready-for-hard-figuring mood.
Overrides: datatype.__get__
(inherited documentation)

__set__(self, dbobj, value)

source code 
Set the attribute managed by this datatype class on instance to value. This will be called by Python on attribute assignment. The __set_from_result__ method does the same thing for data retrieved from the RDBMS. See below.
Overrides: datatype.__set__
(inherited documentation)

__set_from_result__(self, ds, dbobj, value)

source code 
None
Overrides: datatype.__set_from_result__

isset(self, dbobj)

source code 
Returns:
True, if this property is set, otherwise... well.. False.
Overrides: datatype.isset
(inherited documentation)

sql_literal(self, dbobj)

source code 
Return an SQL literal representing the data managed by this property in dbobj.
Returns:
SQL literal as a string.
Overrides: datatype.sql_literal
(inherited documentation)

__select_this_column__(self)

source code 
Indicate whether this column shall be included in SELECT statements. True by default, it will return False for most relationships.
Overrides: datatype.__select_this_column__
(inherited documentation)

__select_after_insert__(self, dbobj)

source code 
Indicate whether this column needs to be SELECTed after the dbobj has been inserted to pick up information supplied by backend as by SQL default values and auto increment columns.
Overrides: datatype.__select_after_insert__
(inherited documentation)