type_and_status¶
Convenience classes to give entities a status, and create the needed related status tables for each entity. Status changes are tracked in a related status history table.
Possible statuses can be defined as an enumeration or as a reference to a table of related statuses.
Enumeration¶
In this setup there is a limited number of possible statuses an object can have, this cannot be changed by the user of the application.
Related status type table¶
In this setup, an additional table with possible status types is created. The user of the application can modify this table and create additional statuses as needed.
- class camelot.model.type_and_status.ChangeStatus(new_status, verbose_name=None)[source]¶
An action that changes the status of an object within a transaction
Parameters: - new_status – the new status of the object
- verbose_name – the name of the action
Before changing the status, the validity of the object will be checked. This state of the action does not depend on the validity of the object, as this might slow down list views too much.
- after_status_change(model_context, obj)[source]¶
Use this method to implement checks or actions that need to happen before the status is changed, but within the transaction
- class camelot.model.type_and_status.Status(enumeration=None, status_history_table=None, status_type_table=None)[source]¶
EntityBuilder that adds a related status table(s) to an Entity.
These additional entities are created :
- a StatusType this is the list of possible statuses an entity can have. If the enumeration parameter is used at construction, no such entity is created, and the list of possible statuses is limited to this enumeration.
- a StatusHistory is the history of statusses an object has had. The Status History refers to which StatusType was valid at a certain point in time.
Parameters: enumeration – if this parameter is used, no StatusType entity is created, but the status type is described by the enumeration. This parameter should be a list of all possible statuses the entity can have
enumeration = [(1, ‘draft’), (2,’ready’)]
Parameters: - status_history_table – the tablename to use to store the status history
- status_type_table – the tablename to use to store the status types
- class camelot.model.type_and_status.StatusFilter(attribute, default=<class 'camelot.admin.action.list_filter.All'>, verbose_name=None, exclusive=True)[source]¶
Filter to be used in a table view to enable filtering on the status of an object. This filter will display all available statuses, and as such, needs not to query the distinct values used in the database to build up it’s widget.
Parameters: attribute – the attribute that holds the status
- class camelot.model.type_and_status.StatusHistory[source]¶
Mixin class to track the history of the status an object has.
- status_datetime For statuses that occur at a specific point in time
- status_from_date For statuses that require a date range
- from_date When a status was enacted or set
- sort_key()[source]¶
Key to be used to sort the status histories to get a single status history at a specific date.
The default order is :
- if status_from_date of history a comes before history b, history a comes before history b
- if history a has a primary key and history b has no primary key, history a comes before history b
- if the primary key of history a is smaller than the primary key of history b, history a comes before history b.
This ensures that the order matches the one of the default sql queries, but it allows changing the status without assigning primary keys yet.
- class camelot.model.type_and_status.StatusMixin[source]¶
This class adds additional methods to classes that have a status. Such as methods to retrieve and modify the status.
- change_status(new_status, status_from_date=None, status_thru_date=datetime.date(2400, 12, 31))[source]¶
Change the status of this object. This method does not start a transaction, but it is advised to run this method in a transaction.
- static current_status_query(status_history, status_class)[source]¶
Parameters: - status_history – the class or columns that represents the status history
- status_class – the class or columns of the class that have a status
Returns: a select statement that looks for the current status of the status_class
- class camelot.model.type_and_status.StatusTypeMixin[source]¶
Mixin class to describe the different statuses an object can have
- class camelot.model.type_and_status.Type(type_table=None, nullable=False, type_verbose_name=None, type_verbose_name_plural=None)[source]¶
EntityBuilder that adds a related type table to an Entity.
An additional Type entity is created, this is the list of possible types an entity can have.
Parameters: - type_table – the tablename used to store the Type entity
- nullable – if the underlying column is nullable
- type_verbose_name – the verbose name of the Type Entity
- type_verbose_name_plural – the verbose plural name of the Type Entity
- class camelot.model.type_and_status.TypeFilter(attribute, default=<class 'camelot.admin.action.list_filter.All'>, verbose_name=None, exclusive=True)[source]¶
Filter to be used in a table view to enable filtering on the type of an object. This filter will display all available types, and as such, needs not to query the distinct values used in the database to build up it’s widget.
Parameters: attribute – the attribute that holds the type