trigger package

Submodules

trigger.apps module

class trigger.apps.TriggerConfig(app_name, app_module)

Bases: django.apps.config.AppConfig

Configuration for the trigger app

label = u'trigger'
name = u'trigger'
verbose_name = u'Trigger'

trigger.handler module

Defines the base class for handling trigger rules and provides apps a way to register handler sub-classes

class trigger.handler.TriggerRuleHandler(trigger_rule_type)

Bases: object

Base class for handling trigger rules

create_configuration(config_dict)

Creates and returns a trigger rule configuration from the given dict

Parameters:config_dict (dict) – The configuration as a dict
Returns:The trigger rule configuration
Return type:trigger.configuration.trigger_rule.TriggerRuleConfiguration

:raises trigger.configuration.exceptions.InvalidTriggerRule: If the configuration is invalid

create_trigger_rule(config_dict, name=None, is_active=True)

Creates and returns a trigger rule model with the given configuration. The returned trigger rule model will be saved in the database.

Parameters:
  • config_dict (dict) – The configuration as a dict
  • name (string) – An optional name for the trigger
  • is_active (bool) – Whether or not the trigger should be active
Returns:

The new trigger rule

Return type:

trigger.models.TriggerRule

Raises:

trigger.configuration.exceptions.InvalidTriggerRule – If the configuration is invalid

trigger.handler.get_trigger_rule_handler(trigger_rule_type)

Returns the trigger rule handler that is registered with the given type

Parameters:trigger_rule_type (string) – The trigger rule type
Returns:The trigger rule handler, possibly None
Return type:trigger.handler.TriggerRuleHandler

:raises trigger.configuration.exceptions.InvalidTriggerType: If the trigger type is invalid

trigger.handler.register_trigger_rule_handler(trigger_rule_handler)

Registers the given trigger rule handler with the given type

Parameters:trigger_rule_handler (trigger.handler.TriggerRuleHandler) – The trigger rule handler

trigger.models module

Defines the models for trigger rules and events

class trigger.models.TriggerEvent(*args, **kwargs)

Bases: django.db.models.base.Model

Represents an event where a trigger occurred

Parameters:
  • type (django.db.models.CharField) – The type of the trigger that occurred
  • rule (django.db.models.ForeignKey) – The rule that triggered this event, possibly None (some events are not triggered by rules)
  • description (django.contrib.postgres.fields.JSONField) – JSON description of the event. This will contain fields specific to the type of the trigger that occurred.
  • occurred (django.db.models.DateTimeField) – When the event occurred
exception DoesNotExist

Bases: django.core.exceptions.ObjectDoesNotExist

exception MultipleObjectsReturned

Bases: django.core.exceptions.MultipleObjectsReturned

batch_set

Accessor to the related objects manager on the reverse side of a many-to-one relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

parent.children is a ReverseManyToOneDescriptor instance.

Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.

description

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

get_next_by_occurred(*moreargs, **morekwargs)
get_previous_by_occurred(*moreargs, **morekwargs)
id

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

job_set

Accessor to the related objects manager on the reverse side of a many-to-one relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

parent.children is a ReverseManyToOneDescriptor instance.

Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.

objects = <trigger.models.TriggerEventManager object>
occurred

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

purgeresults_set

Accessor to the related objects manager on the reverse side of a many-to-one relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

parent.children is a ReverseManyToOneDescriptor instance.

Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.

recipe_set

Accessor to the related objects manager on the reverse side of a many-to-one relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

parent.children is a ReverseManyToOneDescriptor instance.

Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.

rule

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

child.parent is a ForwardManyToOneDescriptor instance.

rule_id

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

type

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

class trigger.models.TriggerEventManager

Bases: django.db.models.manager.Manager

Provides additional methods for handling trigger events

create_trigger_event(trigger_type, rule, description, occurred)

Creates a new trigger event and returns the event model. The given rule model, if not None, must have already been saved in the database (it must have an ID). The returned trigger event model will be saved in the database.

Parameters:
  • trigger_type (str) – The type of the trigger that occurred
  • rule (trigger.models.TriggerRule) – The rule that triggered the event, possibly None
  • description (dict) – The JSON description of the event as a dict
  • occurred (datetime.datetime) – When the event occurred
Returns:

The new trigger event

Return type:

trigger.models.TriggerEvent

get_locked_event(event_id)

Locks and returns the event model for the given ID with no related fields. Caller must be within an atomic transaction.

Parameters:event_id (int) – The event ID
Returns:The event model
Return type:event.models.TriggerEvent
class trigger.models.TriggerRule(*args, **kwargs)

Bases: django.db.models.base.Model

Represents a rule that, when triggered, creates a trigger event

Parameters:
  • type (django.db.models.CharField) – The type of the trigger for the rule
  • name (django.db.models.CharField) – The identifying name of the trigger rule used by clients for queries
  • configuration (django.contrib.postgres.fields.JSONField) – JSON configuration for the rule. This will contain fields specific to the type of the trigger.
  • is_active (django.db.models.BooleanField) – Whether the rule is still active (false once rule is archived)
  • created (django.db.models.DateTimeField) – When the rule was created
  • archived (django.db.models.DateTimeField) – When the rule was archived (no longer active)
  • last_modified (django.db.models.DateTimeField) – When the rule was last modified
exception DoesNotExist

Bases: django.core.exceptions.ObjectDoesNotExist

exception MultipleObjectsReturned

Bases: django.core.exceptions.MultipleObjectsReturned

archived

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

configuration

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

created

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

get_configuration()

Returns the configuration for this trigger rule

Returns:The configuration for this trigger rule
Return type:trigger.configuration.trigger_rule.TriggerRuleConfiguration

:raises trigger.configuration.exceptions.InvalidTriggerType: If the trigger type is invalid

get_next_by_created(*moreargs, **morekwargs)
get_next_by_last_modified(*moreargs, **morekwargs)
get_previous_by_created(*moreargs, **morekwargs)
get_previous_by_last_modified(*moreargs, **morekwargs)
id

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

is_active

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

last_modified

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

name

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

natural_key()

Django method to define the natural key for a trigger rule as the name

Returns:A tuple representing the natural key
Return type:tuple(str,)
objects = <trigger.models.TriggerRuleManager object>
triggerevent_set

Accessor to the related objects manager on the reverse side of a many-to-one relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

parent.children is a ReverseManyToOneDescriptor instance.

Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.

type

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

class trigger.models.TriggerRuleManager

Bases: django.db.models.manager.Manager

Provides additional methods for handling trigger rules

archive_trigger_rule(*args, **kwargs)

Archives the trigger rule (will no longer be active) with the given ID

Parameters:trigger_rule_id (int) – The ID of the trigger rule to archive
create_trigger_rule(trigger_type, configuration, name=u'', is_active=True)

Creates a new trigger rule and returns the rule model. The returned trigger rule model will be saved in the database.

Parameters:
  • trigger_type (str) – The type of this trigger rule
  • configuration (trigger.configuration.TriggerRuleConfiguration) – The rule configuration
  • name (str) – An optional name for the trigger
  • is_active (bool) – Whether or not the trigger should be active
Returns:

The new trigger rule

Return type:

trigger.models.TriggerRule

Raises:

trigger.configuration.exceptions.InvalidTriggerRule – If the configuration is invalid

get_by_natural_key(name)

Django method to retrieve a trigger rule for the given natural key. NOTE: All trigger rule names are NOT unique. This is implemented to allow the loading of defined system trigger rules which do have unique names.

Parameters:name (str) – The name of the trigger rule
Returns:The trigger rule defined by the natural key
Return type:error.models.Error

trigger.serializers module

Defines the serializers for trigger events and rules

class trigger.serializers.TriggerEventBaseSerializerV6(instance=None, data=<class rest_framework.fields.empty>, **kwargs)

Bases: util.rest.ModelIdSerializer

Converts trigger event model fields to REST output.

class trigger.serializers.TriggerEventDetailsSerializerV6(instance=None, data=<class rest_framework.fields.empty>, **kwargs)

Bases: trigger.serializers.TriggerEventBaseSerializerV6

Converts trigger event model fields to REST output.

class trigger.serializers.TriggerEventSerializerV6(instance=None, data=<class rest_framework.fields.empty>, **kwargs)

Bases: trigger.serializers.TriggerEventBaseSerializerV6

Converts trigger event model fields to REST output.

class trigger.serializers.TriggerRuleBaseSerializer(instance=None, data=<class rest_framework.fields.empty>, **kwargs)

Bases: util.rest.ModelIdSerializer

Converts trigger rule model fields to REST output.

class trigger.serializers.TriggerRuleDetailsSerializer(instance=None, data=<class rest_framework.fields.empty>, **kwargs)

Bases: trigger.serializers.TriggerRuleBaseSerializer

Converts trigger rule model fields to REST output.

class trigger.serializers.TriggerRuleSerializer(instance=None, data=<class rest_framework.fields.empty>, **kwargs)

Bases: trigger.serializers.TriggerRuleBaseSerializer

Converts trigger rule model fields to REST output.

Module contents