Camelot comes with a number of built in data models. To avoid boiler plate models needed in almost any application (like Persons, Addresses, etc.), the developer is encouraged to use these data models as a start for developing custom applications.
The camelot.model module contains a number of submodules, each with a specific purpose
To activate such a submodule, the submodule should be imported in the setup_model method of settings class, before the tables are created
def setup_model( self ):
from camelot.core.sql import metadata
metadata.bind = self.ENGINE()
from camelot.model import authentication
from camelot.model import party
from camelot.model import i18n
from camelot.core.orm import setup_all
setup_all( create_tables=True )
Set of classes to store persons, organizations, relationships and contact mechanisms
These structures are modeled like described in ‘The Data Model Resource Book’ by Len Silverston, Chapter 2
The Address to be given to a Party (a Person or an Organization)
Fields :
- city : refers to <class ‘camelot.model.party.City’>
- street1 : VARCHAR(128), required
- street2 : VARCHAR(128), not required
- party_addresses : refers to PartyAddress
Admin with only the Address information and not the Party information
Fields :
- country : refers to <class ‘camelot.model.party.Country’>
Fields :
- party_contact_mechanisms : refers to PartyContactMechanism
- mechanism : VARCHAR(256), required
- party_address : refers to <class ‘camelot.model.party.PartyAddress’>
Fields :
Relation from a directed organization to a director
Relation from employer to employee
The base class for Country and City
Fields :
- customers : refers to SupplierCustomer
- logo : VARCHAR(100), not required
- tax_id : VARCHAR(20), not required
- shareholders : refers to SharedShareholder
- name : VARCHAR(50), required
- employees : refers to EmployerEmployee
- directors : refers to DirectedDirector
- suppliers : refers to SupplierCustomer
Base class for persons and organizations. Use this base class to refer to either persons or organisations in building authentication systems, contact management or CRM
Person represents natural persons
Fields :
- comment : TEXT, not required
- picture : VARCHAR(100), not required
- last_name : VARCHAR(40), required
- suffix : VARCHAR(3), not required
- sex : VARCHAR(1), not required
- passport_expiry_date : DATE, not required
- employers : refers to EmployerEmployee
- first_name : VARCHAR(40), required
- middle_name : VARCHAR(40), not required
- passport_number : VARCHAR(20), not required
- birthdate : DATE, not required
- is_superuser : <class ‘sqlalchemy.types.Boolean’>, not required
- is_staff : <class ‘sqlalchemy.types.Boolean’>, not required
- martial_status : VARCHAR(1), not required
- social_security_number : VARCHAR(12), not required
- personal_title : VARCHAR(10), not required
Relation from a representing party to the person representing the party
Relation from a shared organization to a shareholder
Set of classes to store internationalization data in the database. Camelot applications can be translated by the developer using regular PO files, or by the user. In case the user makes a translation, this translation is stored into the Translation table. This table can be exported to PO files for inclusion in the development cycle.
Keep track of static data loaded into the database. This class keeps track of data inserted into the database by storing the primary key and the class name of the inserted data, and associating this with a fixture key specified by the developer.
The developer can then use the fixture key to find out if this data has been stored in the database, or to update it in future versions of the application.
Only classes which have an integer field as their primary key can be tracked.
Find data that has been stored for a fixture key.
Parameters: |
|
---|---|
Returns: | a instance of type entity, or None if no fixture is found |
Find the fixture key for an object of type entity with primary key
Parameters: |
|
---|---|
Returns: | a string with the fixture_key that refers to this data, None if no such data is found |
Find out if an object was stored in the database through the fixture mechanism and return its fixture_key and fixture_class
Parameters: | obj – the object stored in the database |
---|---|
Returns: | (fixture_key, fixture_class) if the object was registered |
through the fixture mechanism, (None, None) otherwise
Load all fixture keys of a certain entity class in batch.
Parameters: | entity – the class of the stored data |
---|---|
Returns: | a dictionary mapping the primary key of a on object of type entity to a tuple of type (fixture key, fixture class) |
Find the Fixture instance that refers to the data stored for a fixture key.
Parameters: |
|
---|---|
Returns: | a Fixture instance refering to the stored data, or None of no data was found. |
Store data in the database through the fixture mechanism, to be able to keep track of it later.
Parameters: |
|
---|---|
Returns: | an object of type entity, either created or modified |
Remove all data of a certain class from the database, if it was stored through the fixture mechanism.
Parameters: | entity – the class of the stored data |
---|
Remove data from the database, if it was stored through the fixture mechanism.
Parameters: |
|
---|
Keep track of the version the fixtures have in the current database, the subversion revision number is a good candidate to be used as a fixture version.
Returns: | an integer representing the current version, 0 if no version found |
---|
Get the current version of the fixtures in the database for a certain fixture class.
Parameters: | fixture_class – the fixture class for which to get the version |
---|
Set the current version of the fixtures in the database for a certain fixture class.
Parameters: |
|
---|
version
Set of classes to store authentication and permissions
Fields :
- members : refers to <class ‘camelot.model.authentication.AuthenticationMechanism’>
Table with the different roles associated with an AuthenticationGroup
Get the currently logged in :class:’AuthenticationMechanism’
Update the last login of the currently logged in user to now. If there is no AuthenticationGroup yet in the database, create one and add the user to it. This can be used to bootstrap the authentication system and create an admin group and add the user to it.
Parameters: |
|
---|
Most applications need to perform some scheduled jobs to process information. Users need to be able to monitor the functioning of those scheduled jobs.
These classes provide the means to store the result of batch jobs to enable the user to review or plan them.
Fields :
- host : VARCHAR(256), required
- message : TEXT, not required
- type : refers to BatchJobType
If an exception occurs in a batch job, this method can be used to add the stack trace of an exception to the message.
If no arguments are given, sys.exc_traceback is used.
Parameters: |
|
---|
Add strings to the message of this batch job.
Parameters: |
|
---|
‘green’, ...), None if the color needs no change.
Create a new batch job object in a session of its own. This allows flushing the batch job independent from other objects.
Parameters: |
|
---|---|
Returns: | a new BatchJob object |
Verifies if this Batch Job is canceled. Returns True if it is. This method is thus suiteable to call inside a running batch job to verifiy if another user has canceled the running job. Create a batch job object through the create() method to make sure requesting the status does not interfer with the normal session.
Returns: | True or False |
---|
Fields :
- name : VARCHAR(256), required
- parent : refers to BatchJobType
A batch job object can be used as a context manager :
from camelot.model.batch_job import BatchJob, BatchJobType
synchronize = BatchJobType.get_or_create( u'Synchronize' )
with BatchJob.create( synchronize ) as batch_job:
batch_job.add_strings_to_message( [ u'Synchronize part A',
u'Synchronize part B' ] )
batch_job.add_strings_to_message( [ u'Done' ], color = 'green' )
Whenever an exception happens inside the with block, the stack trace of this exception will be written to the bach job object and it’s status will be set to errors. At the end of the with block, the status of the batch job will be set to finished.
The ORM part of the classes that store the change history of objects to the database. The table defined here is used in camelot.core.memento to store the changes.
To prevent this table to be used to store changes, overwrite the camelot.admin.application_admin.ApplicationAdmin.get_memento() method the custom ApplicationAdmin.
Sometimes the built in models don’t have all the fields or relations required for a specific application. Fortunately it is possible to add fields to an existing model on a per application base.
To do so, simply assign the required fields in the application specific model definition, before the tables are created.
party.Person.language = schema.Column( types.Unicode(30) )
metadata.create_all()
p = party.Person( first_name = u'Peter',
last_name = u'Principle',
language = u'English' )
session.flush()