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 )
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.
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()