pyfarm.models.core.mixins module

Mixin Classes

Module containing mixins which can be used by multiple models.

class pyfarm.models.core.mixins.ModelTypes(primary_keys, autoincrementing, columns, required, relationships, mappings)

Bases: tuple


Alias for field number 1


Alias for field number 2


Alias for field number 5


Alias for field number 0


Alias for field number 4


Alias for field number 3

class pyfarm.models.core.mixins.ReprMixin[source]

Bases: object

Mixin which allows model classes to to convert columns into a more easily read object format.

REPR_COLUMNS = NotImplemented
class pyfarm.models.core.mixins.UtilityMixins[source]

Bases: object

Mixins which can be used to produce dictionaries of existing data.

 A dictionary containing key value pairs of attribute names and a function to retrieve the attribute. The function should take a single input and return the value itself. Optionally, you can also use the NotImplemented object to exclude some columns from the results.

Produce a dictionary of existing data in the table

Parameters:unpack_relationships (list, tuple, set, bool) – If True then unpack all relationships. If unpack_relationships is an iterable such as a list or tuple object then only unpack those relationships.
classmethod to_schema()[source]

Produce a dictionary which represents the table’s schema in a basic format

classmethod types()[source]

A classmethod that constructs a namedtuple object with four attributes:

  • primary_keys - set of all primary key(s) names
  • autoincrementing - set of all columns which have autoincrement set
  • columns - set of all column names
  • required - set of all required columns (non-nullable wo/defaults)
  • relationships - not columns themselves but do store relationships
  • mappings - contains a dictionary with each field mapping to a Python type
class pyfarm.models.core.mixins.ValidatePriorityMixin[source]

Bases: object

Mixin that adds a state column and uses a class level STATE_ENUM attribute to assist in validation.

validate_attempts(key, value)[source]

ensures the number of attempts provided is valid

validate_priority(key, value)[source]

ensures the value provided to priority is valid

class pyfarm.models.core.mixins.ValidateWorkStateMixin[source]

Bases: object

STATE_ENUM = NotImplemented
validate_state(key, value)[source]

Ensures that value is a member of STATE_ENUM

validate_state_column(key, value)[source]

validates the state column

class pyfarm.models.core.mixins.WorkStateChangedMixin[source]

Bases: object

Mixin which adds a static method to be used when the model state changes

static state_changed(target, new_value, old_value, initiator)[source]

update the datetime objects depending on the new value