diff --git a/openerp/osv/fields.py b/openerp/osv/fields.py index f55e4b9c027..54d1d1dae6b 100644 --- a/openerp/osv/fields.py +++ b/openerp/osv/fields.py @@ -19,18 +19,19 @@ # ############################################################################## -# . Fields: -# - simple -# - relations (one2many, many2one, many2many) -# - function -# -# Fields Attributes: -# _classic_read: is a classic sql fields -# _type : field type -# readonly -# required -# size -# +""" Fields: + - simple + - relations (one2many, many2one, many2many) + - function + + Fields Attributes: + * _classic_read: is a classic sql fields + * _type : field type + * readonly + * required + * size +""" + import datetime as DT import string import sys @@ -51,6 +52,12 @@ def _symbol_set(symb): class _column(object): + """ Base of all fields, a database column + + An instance of this object is a *description* of a database column. It will + not hold any data, but only provide the methods to manipulate data of an + ORM record or even prepare/update the database to hold such a field of data. + """ _classic_read = True _classic_write = True _prefetch = True @@ -855,6 +862,15 @@ class function(_column): # --------------------------------------------------------- class related(function): + """Field that points to some data inside another field of the current record. + + Example:: + + _columns = { + 'foo_id': fields.many2one('my.foo', 'Foo'), + 'bar': fields.related('frol', 'foo_id', type='char', string='Frol of Foo'), + } + """ def _fnct_search(self, tobj, cr, uid, obj=None, name=None, domain=None, context=None): self._field_get2(cr, uid, obj, context) diff --git a/openerp/osv/orm.py b/openerp/osv/orm.py index 4141176fc5b..9578a4d356b 100644 --- a/openerp/osv/orm.py +++ b/openerp/osv/orm.py @@ -19,24 +19,25 @@ # ############################################################################## -# -# Object relationnal mapping to postgresql module -# . Hierarchical structure -# . Constraints consistency, validations -# . Object meta Data depends on its status -# . Optimised processing by complex query (multiple actions at once) -# . Default fields value -# . Permissions optimisation -# . Persistant object: DB postgresql -# . Datas conversions -# . Multi-level caching system -# . 2 different inheritancies -# . Fields: -# - classicals (varchar, integer, boolean, ...) -# - relations (one2many, many2one, many2many) -# - functions -# -# +""" + Object relational mapping to database (postgresql) module + * Hierarchical structure + * Constraints consistency, validations + * Object meta Data depends on its status + * Optimised processing by complex query (multiple actions at once) + * Default fields value + * Permissions optimisation + * Persistant object: DB postgresql + * Datas conversions + * Multi-level caching system + * 2 different inheritancies + * Fields: + - classicals (varchar, integer, boolean, ...) + - relations (one2many, many2one, many2many) + - functions + +""" + import calendar import copy import datetime @@ -123,8 +124,9 @@ class except_orm(Exception): class BrowseRecordError(Exception): pass -# Readonly python database object browser class browse_null(object): + """ Readonly python database object browser + """ def __init__(self): self.id = False @@ -152,6 +154,11 @@ class browse_null(object): # TODO: execute an object method on browse_record_list # class browse_record_list(list): + """ Collection of browse objects + + Such an instance will be returned when doing a ``browse([ids..])`` + and will be iterable, yielding browse() objects + """ def __init__(self, lst, context=None): if not context: @@ -161,13 +168,25 @@ class browse_record_list(list): class browse_record(object): + """ An object that behaves like a row of an object's table. + It has attributes after the columns of the corresponding object. + + Examples:: + + uobj = pool.get('res.users') + user_rec = uobj.browse(cr, uid, 104) + name = user_rec.name + """ logger = netsvc.Logger() def __init__(self, cr, uid, id, table, cache, context=None, list_class=None, fields_process=None): - ''' - table : the object (inherited from orm) - context : dictionary with an optional context - ''' + """ + @param cache a dictionary of model->field->data to be shared accross browse + objects, thus reducing the SQL read()s . It can speed up things a lot, + but also be disastrous if not discarded after write()/unlink() operations + @param table the object (inherited from orm) + @param context dictionary with an optional context + """ if fields_process is None: fields_process = {} if context is None: @@ -361,10 +380,10 @@ class browse_record(object): def get_pg_type(f): - ''' + """ returns a tuple (type returned by postgres when the column was created, type expression to create the column) - ''' + """ type_dict = { fields.boolean: 'bool', @@ -725,7 +744,7 @@ class orm_template(object): :param cr: database cursor :param user: current user id - :param select: id or list of ids + :param select: id or list of ids. :param context: context arguments, like lang, time zone :rtype: object or list of objects requested diff --git a/openerp/tools/misc.py b/openerp/tools/misc.py index 4167befd42d..a79bbb0cf49 100644 --- a/openerp/tools/misc.py +++ b/openerp/tools/misc.py @@ -124,16 +124,18 @@ def exec_command_pipe(name, *args): def file_open(name, mode="r", subdir='addons', pathinfo=False): """Open a file from the OpenERP root, using a subdir folder. + Example:: + >>> file_open('hr/report/timesheer.xsl') >>> file_open('addons/hr/report/timesheet.xsl') >>> file_open('../../base/report/rml_template.xsl', subdir='addons/hr/report', pathinfo=True) - @param name: name of the file - @param mode: file open mode - @param subdir: subdirectory - @param pathinfo: if True returns tupple (fileobject, filepath) + @param name name of the file + @param mode file open mode + @param subdir subdirectory + @param pathinfo if True returns tupple (fileobject, filepath) - @return: fileobject if pathinfo is False else (fileobject, filepath) + @return fileobject if pathinfo is False else (fileobject, filepath) """ import openerp.modules as addons adps = addons.module.ad_paths @@ -217,7 +219,7 @@ def flatten(list): """Flatten a list of elements into a uniqu list Author: Christophe Simonis (christophe@tinyerp.com) - Examples: + Examples:: >>> flatten(['a']) ['a'] >>> flatten('b') @@ -246,6 +248,8 @@ def flatten(list): def reverse_enumerate(l): """Like enumerate but in the other sens + + Usage:: >>> a = ['a', 'b', 'c'] >>> it = reverse_enumerate(a) >>> it.next() @@ -285,16 +289,14 @@ priorities = { } def html2plaintext(html, body_id=None, encoding='utf-8'): + """ From an HTML text, convert the HTML to plain text. + If @param body_id is provided then this is the tag where the + body (not necessarily
) starts. + """ ## (c) Fry-IT, www.fry-it.com, 2007 ##