rattail.trainwreck.handler

Trainwreck Handler

class rattail.trainwreck.handler.TrainwreckHandler(config, **kwargs)[source]

Handler for Trainwreck data and databases.

current_years()[source]

Returns the number of years which should be kept in the “current” Trainwreck DB.

Note that this refers to the “max” number of years. Rotation is done on a yearly basis, so for instance if the number of years to keep current is 2 (the default), then the actual amount of data in the current DB will vary between 1 years (immediately after Jan 1 pruning) and 2 years (immediately before Jan 1).

In other words if today is Jan 2, and pruning has already occurred, then current DB would have all of last year plus only a day or two from this year. But by the end of this year it will (still) have all of last year, plus all of this year.

engine_is_hidden(key)[source]

Returns a boolean indicating if the given Trainwreck database engine is configured to be hidden from the user interface.

get_hidden_engine_keys()[source]

Return a list of database engine keys which are configured to be hidden from the user interface.

get_model(**kwargs)[source]

Return the data model for Trainwreck.

get_newest_transaction_date(session)[source]

Query a Trainwreck database to determine the date of the “newest” transaction it contains.

Parameters:

session – SQLAlchemy session for a Trainwreck database.

Returns:

A datetime.date instance representing the newest transaction date contained by the database.

get_oldest_transaction_date(session)[source]

Query a Trainwreck database to determine the date of the “oldest” transaction it contains.

Parameters:

session – SQLAlchemy session for a Trainwreck database.

Returns:

A datetime.date instance representing the oldest transaction date contained by the database.

get_trainwreck_engines(include_hidden=True)[source]

Return an “ordered” dict with configured trainwreck DB engines. Keys of the dict will correspond to the config keys for each DB, values will be the engines.

Parameters:

include_hidden – Flag indicating whether the result should include engines which are marked as hidden. Note that hidden engines are included by default.

Returns:

An OrderedDict instance.

make_session(dbkey='default', **kwargs)[source]

Make a session for a Trainwreck DB.

use_rotation()[source]

Returns boolean indicating whether rotation should be used, for the Trainwreck DB(s).