assembl.lib.decl_enums module

Enumerations that can be stored in the database.

Mostly from http://techspot.zzzeek.org/2011/01/14/the-enum-recipe/

class assembl.lib.decl_enums.DeclEnum[source]

Bases: object

Declarative enumeration.

class assembl.lib.decl_enums.DeclEnumType(enum, **kwargs)[source]

Bases: sqlalchemy.sql.sqltypes.SchemaType, sqlalchemy.sql.type_api.TypeDecorator

copy(**kw)[source]

Produce a copy of this TypeDecorator instance.

This is a shallow copy and is provided to fulfill part of the TypeEngine contract. It usually does not need to be overridden unless the user-defined TypeDecorator has local state that should be deep-copied.

process_bind_param(value, dialect)[source]

Receive a bound parameter value to be converted.

Subclasses override this method to return the value that should be passed along to the underlying TypeEngine object, and from there to the DBAPI execute() method.

The operation could be anything desired to perform custom behavior, such as transforming or serializing data. This could also be used as a hook for validating logic.

This operation should be designed with the reverse operation in mind, which would be the process_result_value method of this class.

Parameters
  • value – Data to operate upon, of any type expected by this method in the subclass. Can be None.

  • dialect – the Dialect in use.

process_result_value(value, dialect)[source]

Receive a result-row column value to be converted.

Subclasses should implement this method to operate on data fetched from the database.

Subclasses override this method to return the value that should be passed back to the application, given a value that is already processed by the underlying TypeEngine object, originally from the DBAPI cursor method fetchone() or similar.

The operation could be anything desired to perform custom behavior, such as transforming or serializing data. This could also be used as a hook for validating logic.

Parameters
  • value – Data to operate upon, of any type expected by this method in the subclass. Can be None.

  • dialect – the Dialect in use.

This operation should be designed to be reversible by the “process_bind_param” method of this class.

class assembl.lib.decl_enums.EnumMeta(classname, bases, dict_)[source]

Bases: type

Generate new DeclEnum classes.

class assembl.lib.decl_enums.EnumSymbol(cls_, name, value, description)[source]

Bases: object

Define a fixed symbol tied to a parent class.

class assembl.lib.decl_enums.UpdatablePgEnum(*enums, ordered=True, **kw)[source]

Bases: sqlalchemy.dialects.postgresql.base.ENUM

A Postgres-native enum type that will add values to the native enum when the Python Enum is updated.

create(bind=None, checkfirst=True)[source]

Emit CREATE TYPE for this _postgresql.ENUM.

If the underlying dialect does not support PostgreSQL CREATE TYPE, no action is taken.

Parameters
  • bind – a connectable _engine.Engine, _engine.Connection, or similar object to emit SQL.

  • checkfirst – if True, a query against the PG catalog will be first performed to see if the type does not exist already before creating.

update_type(bind)[source]

Update the postgres enum to match the values of the ENUM