Public Member Functions | Public Attributes

Koo::Model::Group::RecordGroup Class Reference

The RecordGroup class manages a list of records. More...

List of all members.

Public Member Functions

def __init__
 Creates a new RecordGroup object.
def setLoadOneByOne
 Sets wether data loading should be done on record chunks or one by one.
def fieldType
 Returns a string with the name of the type of a given field.
def save
 Saves all the records.
def modifiedRecords
 Returns a list with all modified records.
def written
 This function executes the 'onWriteFunction' function in the server.
def loadFromValues
 Adds a list of records as specified by 'values'.
def load
 Creates as many records as len(ids) with the ids[x] as id.
def clear
 Clears the list of records.
def context
 Returns a copy of the current context.
def setContext
 Sets the context that will be used for RPC calls.
def add
 Adds a record to the list.
def create
 Creates a new record of the same type of the records in the group.
def removeRecord
 Removes a record from the record group but not from the server.
def removeRecords
 Remove a list of records from the record group but not from the server.
def remove
 Removes a record from the record group but not from the server.
def addFields
 Adds the specified fields to the record group.
def ensureAllLoaded
 Ensures all records in the group are loaded.
def unloadedIds
 Returns the list of ids that have not been loaded yet.
def loadedRecords
 Returns the list of loaded records.
def ids
 Returns a list with all ids.
def newRecords
 Returns a list with all new records.
def count
 Returns the number of records in this group.
def modelById
 Returns the record with id 'id'.
def modelByIndex
 Returns the record at the specified row number.
def indexOfRecord
 Returns the row number of the given record.
def indexOfId
 Returns the row number of the given id.
def recordExists
 Returns True if the given record exists in the group.
def recordById
 Returns the record with id 'id'.
def recordByIndex
 Returns a Record object for the given row.
def isWizard
 Returns True if the RecordGroup handles information of a wizard.
def ensureModelLoaded
 Checks whether the specified record is fully loaded and loads it if necessary.
def setDomain
 Allows setting the domain for this group of records.
def domain
 Returns the current domain.
def setFilter
 Allows setting a filter for this group of records.
def filter
 Returns the current filter.
def setDomainForEmptyGroup
 Disables record loading by setting domain to [('id','in',[])].
def isDomainForEmptyGroup
 Returns True if domain is [('id','in',[])].
def update
 Reload the record group with current selected sort field, order, domain and filter.
def ensureUpdated
 Ensures the group is updated.
def sort
 Sorts the group by the given field name.
def cancel
 Removes all new records and marks all modified ones as not loaded.
def freeRecord
 Removes a record from the list (but not the record from the database).
def isModified
 Returns True if any of the records in the group has been modified.
def isRecordModified
 Returns True if the given record has been modified.
def isFieldRequired
 Returns True if the given field is required in the RecordGroup, otherwise returns False.

Public Attributes

 updated
 Make it reload again.

Detailed Description

The RecordGroup class manages a list of records.

Provides functions for loading, storing and creating new objects of the same type. The 'fields' property stores a dictionary of dictionaries, each of which contains information about a field. This information includes the data type ('type'), its name ('name') and other attributes. The 'fieldObjects' property stores the classes responsible for managing the values which are finally stored on the 'values' dictionary in the Model

The group can also be sorted by any of it's fields. Two sorting methods are provided: SortVisibleItems and SortAllItems. SortVisibleItems is usually faster for a small number of elements as sorting is handled on the client side, but only those loaded are considered in the sorting. SortAllItems, sorts items in the server so all items are considered. Although this would cost a lot when there are thousands of items, only some of them are loaded and the rest are loaded on demand.

Note that by default the group will handle (and eventually load) all records that match the conditions imposed by 'domain' and 'filter'. Those are empty by default so creating RecordGroup('res.parnter') and iterating through it's items will return all partners in the database. If you want to ensure that the group is kept completely empty, you can call setAllowRecordLoading( False ) which is equivalent to calling setFilter() with a filter that no records match, but without the overhead of querying the server.

RecordGroup will emit several kinds of signals on certain events.

Definition at line 68 of file Group.py.


Member Function Documentation

def Koo::Model::Group::RecordGroup::__init__ (   self,
  resource,
  fields = None,
  ids = None,
  parent = None,
  context = None 
)

Creates a new RecordGroup object.

Parameters:
resource Name of the model to load. Such as 'res.partner'.
fields Dictionary with the fields to load. This value typically comes from the server.
ids Record identifiers to load in the group.
parent Only used if this RecordGroup serves as a relation to another model. Otherwise it's None.
context Context for RPC calls.

Definition at line 84 of file Group.py.

def Koo::Model::Group::RecordGroup::addFields (   self,
  fields 
)

Adds the specified fields to the record group.

Note that it updates 'fields' and 'fieldObjects' in the group. 'fields' is a dict of dicts as typically returned by the server.

Definition at line 461 of file Group.py.

def Koo::Model::Group::RecordGroup::cancel (   self  ) 

Removes all new records and marks all modified ones as not loaded.

Definition at line 869 of file Group.py.

def Koo::Model::Group::RecordGroup::clear (   self  ) 

Clears the list of records.

It doesn't remove them.

Definition at line 312 of file Group.py.

def Koo::Model::Group::RecordGroup::count (   self  ) 

Returns the number of records in this group.

Definition at line 531 of file Group.py.

def Koo::Model::Group::RecordGroup::create (   self,
  default = True,
  position = -1,
  domain = None,
  context = None 
)

Creates a new record of the same type of the records in the group.

If 'default' is true, the record is filled in with default values. 'domain' and 'context' are only used if default is true.

Definition at line 355 of file Group.py.

def Koo::Model::Group::RecordGroup::domain (   self  ) 

Returns the current domain.

Definition at line 665 of file Group.py.

def Koo::Model::Group::RecordGroup::ensureAllLoaded (   self  ) 

Ensures all records in the group are loaded.

Definition at line 475 of file Group.py.

def Koo::Model::Group::RecordGroup::ensureModelLoaded (   self,
  record 
)

Checks whether the specified record is fully loaded and loads it if necessary.

Definition at line 612 of file Group.py.

def Koo::Model::Group::RecordGroup::ensureUpdated (   self  ) 

Ensures the group is updated.

Definition at line 709 of file Group.py.

def Koo::Model::Group::RecordGroup::fieldType (   self,
  fieldName 
)

Returns a string with the name of the type of a given field.

Such as 'char'.

Definition at line 184 of file Group.py.

def Koo::Model::Group::RecordGroup::filter (   self  ) 

Returns the current filter.

Definition at line 680 of file Group.py.

def Koo::Model::Group::RecordGroup::freeRecord (   self,
  record 
)

Removes a record from the list (but not the record from the database).

This function is used to take care signals are disconnected.

Definition at line 883 of file Group.py.

def Koo::Model::Group::RecordGroup::ids (   self  ) 

Returns a list with all ids.

Definition at line 510 of file Group.py.

def Koo::Model::Group::RecordGroup::indexOfId (   self,
  id 
)

Returns the row number of the given id.

If the id doesn't exist it returns -1.

Definition at line 564 of file Group.py.

def Koo::Model::Group::RecordGroup::indexOfRecord (   self,
  record 
)

Returns the row number of the given record.

Note that the record must be in the group. Otherwise an exception is risen.

Definition at line 556 of file Group.py.

def Koo::Model::Group::RecordGroup::isFieldRequired (   self,
  fieldName 
)

Returns True if the given field is required in the RecordGroup, otherwise returns False.

Note that this is a flag for the whole group, but each record could have different values depending on its state.

Definition at line 910 of file Group.py.

def Koo::Model::Group::RecordGroup::isModified (   self  ) 

Returns True if any of the records in the group has been modified.

Definition at line 890 of file Group.py.

def Koo::Model::Group::RecordGroup::isRecordModified (   self,
  id 
)

Returns True if the given record has been modified.

Definition at line 898 of file Group.py.

def Koo::Model::Group::RecordGroup::isWizard (   self  ) 

Returns True if the RecordGroup handles information of a wizard.

Definition at line 607 of file Group.py.

def Koo::Model::Group::RecordGroup::load (   self,
  ids,
  addOnTop = False 
)

Creates as many records as len(ids) with the ids[x] as id.

'ids' needs to be a list of identifiers. The addFields() function can be used later to load the necessary fields for each record.

Definition at line 279 of file Group.py.

def Koo::Model::Group::RecordGroup::loadedRecords (   self  ) 

Returns the list of loaded records.

The list won't include new records.

Definition at line 501 of file Group.py.

def Koo::Model::Group::RecordGroup::loadFromValues (   self,
  values 
)

Adds a list of records as specified by 'values'.

'values' has to be a list of dictionaries, each of which containing fields names -> values. At least key 'id' needs to be in all dictionaries.

Definition at line 264 of file Group.py.

def Koo::Model::Group::RecordGroup::modelById (   self,
  id 
)

Returns the record with id 'id'.

You can use [] instead. Note that it will check if the record is loaded and load it if not.

Definition at line 542 of file Group.py.

def Koo::Model::Group::RecordGroup::modelByIndex (   self,
  row 
)

Returns the record at the specified row number.

Definition at line 550 of file Group.py.

def Koo::Model::Group::RecordGroup::newRecords (   self  ) 

Returns a list with all new records.

Definition at line 520 of file Group.py.

def Koo::Model::Group::RecordGroup::recordById (   self,
  id 
)

Returns the record with id 'id'.

You can use [] instead. Note that it will return the record but won't try to load it.

Definition at line 581 of file Group.py.

def Koo::Model::Group::RecordGroup::recordByIndex (   self,
  row 
)

Returns a Record object for the given row.

Definition at line 595 of file Group.py.

def Koo::Model::Group::RecordGroup::recordExists (   self,
  record 
)

Returns True if the given record exists in the group.

Definition at line 576 of file Group.py.

def Koo::Model::Group::RecordGroup::remove (   self,
  record 
)

Removes a record from the record group but not from the server.

If the record doesn't exist it will ignore it silently.

Definition at line 444 of file Group.py.

def Koo::Model::Group::RecordGroup::removeRecord (   self,
  record 
)

Removes a record from the record group but not from the server.

If the record doesn't exist it will ignore it silently.

Definition at line 392 of file Group.py.

def Koo::Model::Group::RecordGroup::removeRecords (   self,
  records 
)

Remove a list of records from the record group but not from the server.

If a record doesn't exist it will ignore it silently.

Definition at line 413 of file Group.py.

def Koo::Model::Group::RecordGroup::save (   self  ) 

Saves all the records.

Note that there will be one request to the server per modified or created record.

Definition at line 202 of file Group.py.

def Koo::Model::Group::RecordGroup::setContext (   self,
  context 
)

Sets the context that will be used for RPC calls.

Definition at line 329 of file Group.py.

def Koo::Model::Group::RecordGroup::setDomain (   self,
  value 
)

Allows setting the domain for this group of records.

Definition at line 653 of file Group.py.

def Koo::Model::Group::RecordGroup::setDomainForEmptyGroup (   self  ) 

Disables record loading by setting domain to [('id','in',[])].

RecordGroup will optimize the case when domain + filter = [('id','in',[])] by not even querying the server and searching ids. It will simply consider the result is [] and thus the group will be kept empty.

Domain may be changed using setDomain() function.

Definition at line 690 of file Group.py.

def Koo::Model::Group::RecordGroup::setFilter (   self,
  value 
)

Allows setting a filter for this group of records.

The filter is conatenated to the domain to further restrict the records of the group.

Definition at line 672 of file Group.py.

def Koo::Model::Group::RecordGroup::setLoadOneByOne (   self,
  value 
)

Sets wether data loading should be done on record chunks or one by one.

Setting value to True, will make the RecordGroup ignore the current 'limit' property, and load records by one by, instead. If set to False (the default) it will load records in groups of 'limit' (80, by default).

In some cases (widgets that show multiple records) it's better to load in chunks, in other cases, it's better to load one by one.

Definition at line 140 of file Group.py.

def Koo::Model::Group::RecordGroup::sort (   self,
  field,
  order 
)

Sorts the group by the given field name.

Definition at line 715 of file Group.py.

def Koo::Model::Group::RecordGroup::unloadedIds (   self  ) 

Returns the list of ids that have not been loaded yet.

The list won't include new records as those have id 0 or None.

Definition at line 489 of file Group.py.

def Koo::Model::Group::RecordGroup::written (   self,
  editedId 
)

This function executes the 'onWriteFunction' function in the server.

If there is a 'onWriteFunction' function associated with the model type handled by this record group it will be executed. 'editedId' should provide the id of the just saved record.

This functionality is provided here instead of on the record because the remote function might update some other records, and they need to be (re)loaded.

Definition at line 224 of file Group.py.


The documentation for this class was generated from the following file:
Generated by Doxygen