types

Camelot extends the SQLAlchemy column types with a number of its own column types. Those field types are automatically mapped to a specific delegate taking care of the visualisation.

Those fields are stored in the camelot.types module.

class camelot.types.Code(parts, separator=u'.', length=None, **kwargs)[source]

SQLAlchemy column type to store codes. Where a code is a list of strings on which a regular expression can be enforced.

This column type accepts and returns a list of strings and stores them as a string joined with points.

eg: ['08', 'AB'] is stored as 08.AB

../../_images/CodeEditor_editable.png
Parameters:
  • parts – a list of input masks specifying the mask for each part, eg ['99', 'AA']. For valid input masks, see QLineEdit
  • separator – a string that will be used to separate the different parts in the GUI and in the database
  • length – the size of the underlying string field in the database, if no length is specified, it will be calculated from the parts
impl

alias of Unicode

class camelot.types.Color[source]

The Color field returns and accepts tuples of the form (r,g,b,a) where r,g,b,a are integers between 0 and 255. The color is stored as an hexadecimal string of the form AARRGGBB into the database, where AA is the transparency, RR is red, GG is green BB is blue:

class MovieType( Entity ):
    color = Column( camelot.types.Color() )
../../_images/ColorEditor_editable.png

The colors are stored in the database as strings.

Use:

QColor(*color) 

to convert a color tuple to a QColor.

impl

alias of Unicode

class camelot.types.Enumeration(choices=[], **kwargs)[source]

The enumeration field stores integers in the database, but represents them as strings. This allows efficient storage and querying while preserving readable code.

Typical use of this field would be a status field.

Enumeration fields are visualized as a combo box, where the labels in the combo box are the capitalized strings:

class Movie(Entity):
  title = Column( Unicode(60), nullable = False )
  state = Column( camelot.types.Enumeration([(1,'planned'), (2,'recording'), (3,'finished'), (4,'canceled')]), 
                  index = True, nullable = False, default = 'planning' )
../../_images/ChoicesEditor_editable.png

If None should be a possible value of the enumeration, add (None, None) to the list of possible enumerations. None will be presented as empty in the GUI.

Parameters:choices – is a list of tuples. each tuple contains an integer and its

associated string. such as

choices = [(1,'draft'), (2,'approved')]
impl

alias of Integer

class camelot.types.File(max_length=100, upload_to=u'', storage=<class 'camelot.core.files.storage.Storage'>, **kwargs)[source]

Sqlalchemy column type to store files. Only the location of the file is stored

This column type accepts and returns a StoredFile. The name of the file is stored as a string in the database. A subdirectory upload_to can be specified:

class Movie( Entity ):
  script = Column( camelot.types.File( upload_to = 'script' ) )
../../_images/FileEditor_editable.png

Retrieving the actual storage from a File field can be a little cumbersome. The easy way is taking it from the field attributes, in which it will be put by default. If no field attributes are available at the location where the storage is needed, eg in some function doing document processing, one needs to go through SQLAlchemy to retrieve it.

For an ‘task’ object with a File field named ‘document’, the storage can be retrieved:

from sqlalchemy import orm

task_mapper = orm.object_mapper( task )
document_property = task_mapper.get_property('document')
storage = document_property.columns[0].type.storage
Parameters:max_length – the maximum length of the name of the file that will

be saved in the database.

Parameters:upload_to – a subdirectory in the Storage, in which the the file

should be stored.

Parameters:storage – an alternative storage to use for this field.
impl

alias of Unicode

stored_file_implementation

alias of StoredFile

class camelot.types.Image(max_length=100, upload_to=u'', storage=<class 'camelot.core.files.storage.Storage'>, **kwargs)[source]

Sqlalchemy column type to store images

This column type accepts and returns a StoredImage, and stores them in the directory specified by settings.CAMELOT_MEDIA_ROOT. The name of the file is stored as a string in the database.

The Image field type provides the same functionallity as the File field type, but the files stored should be images.

../../_images/ImageEditor_editable.png
stored_file_implementation

alias of StoredImage

class camelot.types.Language[source]

The languages are stored as a string in the database of the form language*(_*country), where :

  • language is a lowercase, two-letter, ISO 639 language code,
  • territory is an uppercase, two-letter, ISO 3166 country code

This used to be implemented using babel, but this was too slow and used too much memory, so now it’s implemented using QT.

impl

alias of Unicode

class camelot.types.Rating(*args, **kwargs)[source]

The rating field is an integer field that is visualized as a number of stars that can be selected:

class Movie( Entity ):
  title = Column( Unicode(60), nullable = False )
  rating = Column( camelot.types.Rating() )
../../_images/StarEditor_editable.png
impl

alias of Integer

class camelot.types.RichText(*args, **kwargs)[source]

RichText fields are unlimited text fields which contain html. The html will be rendered in a rich text editor.

../../_images/RichTextEditor_editable.png
impl

alias of UnicodeText

class camelot.types.VirtualAddress(*args, **kwargs)[source]

A single field that can be used to enter phone numbers, fax numbers, email addresses, im addresses. The editor provides soft validation of the data entered. The address or number is stored as a string in the database.

This column type accepts and returns tuples of strings, the first string is the virtual_address_type, and the second the address itself.

eg: ('email','project-camelot@conceptive.be') is stored as email://project-camelot@conceptive.be

../../_images/virtualaddress_editor.png
impl

alias of Unicode

Previous topic

test_proxy

Next topic

view

This Page