Autodocumentation of the Conditionals module

Models

Condition models.

class concord.conditionals.models.ApprovalCondition(*args, **kwargs)

Approval Condition class.

exception DoesNotExist
exception MultipleObjectsReturned
approve()

Approve a condition.

condition_status()

This method returns one of status ‘approved’, ‘rejected’, or ‘waiting’, after checking the condition for its unqiue status logic.

classmethod configurable_fields()

All conditions must supply their own version of the configurable_fields method, which should return a dict with field names as keys and field objects as values.

description_for_passing_condition(fill_dict=None)

This method returns a verbose, human-readable description of what will fulfill this condition. It optionally accepts permission data from the configured condition_template to be more precise about who can do what.

display_fields()

This method returns a list of fields and their values which can be shown to the user. Some overlap with get_configurable_fields_with_data since in many cases we’re just showing the configured fields, but some data may be specific to the condition instance. Note that we do not, for now, return permission data.

display_status()

This method returns a more verbose, human-readable description of the condition status, after checking the condition for its unique status logic.

reject()

Reject a condition.

class concord.conditionals.models.ConditionModel(*args, **kwargs)

Attributes:

action: integer representing the pk of the action that triggered the creation of this condition source_id : consists of a type and a pk, separated by a _, for example “perm_” + str(permission_pk) or

owner_” + str(community_pk)

abstract condition_status()

This method returns one of status ‘approved’, ‘rejected’, or ‘waiting’, after checking the condition for its unqiue status logic.

abstract classmethod configurable_fields()

All conditions must supply their own version of the configurable_fields method, which should return a dict with field names as keys and field objects as values.

abstract description_for_passing_condition(fill_dict)

This method returns a verbose, human-readable description of what will fulfill this condition. It optionally accepts permission data from the configured condition_template to be more precise about who can do what.

abstract display_fields()

This method returns a list of fields and their values which can be shown to the user. Some overlap with get_configurable_fields_with_data since in many cases we’re just showing the configured fields, but some data may be specific to the condition instance. Note that we do not, for now, return permission data.

abstract display_status()

This method returns a more verbose, human-readable description of the condition status, after checking the condition for its unique status logic.

get_action()

Get action associated with condition instance.

classmethod get_configurable_field_names()

Return field names as list.

classmethod get_configurable_fields()

Returns field values as list instead of dict

get_configurable_fields_with_data(permission_data=None)

Returns form_dict with condition data set as value.

get_display_string()

Get display text describing condition..

classmethod get_form_dict_for_field(field)

Get dictionary with form data for supplied field.

get_model_name()

Get name of condition model.

get_name()

Get name of condition.

initialize_condition(*args, **kwargs)

Called when creating the condition, and passed condition_data and permission data.

user_condition_status(user)

User condition status is a shortcut which helps us determine if a user can take an action on a condition without actually creating an action. This is useful in determining what to show the user on the front-end. We assume that by the time user_condition_status is called the user has passed the permissions system, and so this status is to check instance-specific issues, like preventing a person who has already voted from voting again.

class concord.conditionals.models.ConsensusCondition(*args, **kwargs)

Consensus Condition class.

exception DoesNotExist
exception MultipleObjectsReturned
condition_status()

This method returns one of status ‘approved’, ‘rejected’, or ‘waiting’, after checking the condition for its unqiue status logic.

classmethod configurable_fields()

Gets fields on condition which may be configured by user.

description_for_passing_condition(fill_dict=None)

Gets plain English description of what must be done to pass the condition.

display_fields()

Gets condition fields in form dict format, for displaying in the condition component.

display_status()

Gets ‘plain English’ display of status.

initialize_condition(target, condition_data, permission_data, leadership_type)

Called when creating the condition, and passed condition_data and permission data.

class concord.conditionals.models.VoteCondition(*args, **kwargs)

Vote Condition class.

exception DoesNotExist
exception MultipleObjectsReturned
add_vote(vote)

Increments vote depending on vote type.

add_vote_record(actor)

Adds vote to record.

condition_status()

Gets status of condition.

classmethod configurable_fields()

Gets fields on condition which may be configured by user.

current_results()

Get the current results of the vote.

current_standing()

If voting ended right now, returns what the status would be.

describe_voting_period()

Gets human readable description of voting period.

description_for_passing_condition(fill_dict=None)

Gets plain English description of what must be done to pass the condition.

display_fields()

Gets condition fields in form dict format.

display_status()

Gets ‘plain English’ display of status.

get_timeout()

Get when condition closes, aka the voting deadline.

has_voted(actor)

Returns True if actor has voted, otherwise False.

user_condition_status(user)

Checks whether a user has voted already.

voting_deadline()

Gets deadline of vote given starting point and length of vote.

voting_time_remaining()

Gets time remaining to vote.

yeas_have_majority()

Helper method, returns True if yeas currently have majority.

yeas_have_plurality()

Helper method, returns True if yeas currently have plurality.

concord.conditionals.models.conditionModel

alias of concord.conditionals.models.ConsensusCondition

concord.conditionals.models.retry_action(sender, instance, created, **kwargs)

Signal handler which retries the corresponding action or action container when condition has been updated.

State Changes

State Changes for conditional models

class concord.conditionals.state_changes.AddVoteStateChange(vote)

State change for adding a vote.

description_past_tense()

Returns the description of the state change object, in past tense.

description_present_tense()

Returns the description of the state change object, in present tense.

classmethod get_allowable_targets()

Returns the classes that an action of this type may target.

implement(actor, target)

Method that carries out the change of state.

validate(actor, target)

To validate the vote, we need to check that: a) the voter hasn’t voted before b) if the vote is abstain, abstentions are allowed

class concord.conditionals.state_changes.ApproveStateChange

State change for approving a condition.

description_past_tense()

Returns the description of the state change object, in past tense.

description_present_tense()

Returns the description of the state change object, in present tense.

classmethod get_allowable_targets()

Returns the classes that an action of this type may target.

implement(actor, target)

Method that carries out the change of state.

validate(actor, target)

Method to check whether the data provided to a change object in an action is valid for the change object. Optional exclude_fields tells us not to validate the given field.

class concord.conditionals.state_changes.RejectStateChange

State change for rejecting a condition..

description_past_tense()

Returns the description of the state change object, in past tense.

description_present_tense()

Returns the description of the state change object, in present tense.

classmethod get_allowable_targets()

Returns the classes that an action of this type may target.

implement(actor, target)

Method that carries out the change of state.

validate(actor, target)

Checks if actor is the same user who sent the action that triggered the condition and, unless self approval is allowed, rejects them as invalid.

class concord.conditionals.state_changes.ResolveConsensusStateChange

State change for resolving a consensus condition.

description_past_tense()

Returns the description of the state change object, in past tense.

description_present_tense()

Returns the description of the state change object, in present tense.

classmethod get_allowable_targets()

Returns the classes that an action of this type may target.

implement(actor, target)

Method that carries out the change of state.

validate(actor, target)

Checks that the actor is a participant.

class concord.conditionals.state_changes.RespondConsensusStateChange(response)

State change for responding to a consensus condition

description_past_tense()

Returns the description of the state change object, in past tense.

description_present_tense()

Returns the description of the state change object, in present tense.

classmethod get_allowable_targets()

Returns the classes that an action of this type may target.

implement(actor, target)

Method that carries out the change of state.

validate(actor, target)

Checks that the actor is a participant.

class concord.conditionals.state_changes.SetConditionOnActionStateChange(*, condition_type, condition_data=None, permission_data=None, permission_pk=None, community_pk=None, leadership_type=None)

State change which actually creates a condition item associated with a specific action. I’m not actually 100% sure this should be a state change, since as far as I can tell this will always be triggered by the system internally, but we’re doing it this way for now. Also not sure if this should be split up into permission condition and leadership condition.

generate_source_id()

Generates a source_id to use when creating condition item.

classmethod get_allowable_targets()

Returns the classes that an action of this type may target.

get_condition_class()

Gets the condition class object given the condition type.

get_condition_verb()

Get the verb of the associated condition.

get_owner()

The owner of the condition should be the community in which it is created. For now, this means looking up permission and getting owner, or using community if community is set.

Note that if multiple community models are being used, and the community pk passed in is not the primary/default model, this will break.

implement(actor, target)

Method that carries out the change of state.

validate(actor, target)

Method to check whether the data provided to a change object in an action is valid for the change object. Optional exclude_fields tells us not to validate the given field.

Client

Clients for conditionals.

class concord.conditionals.client.ApprovalConditionClient(actor=None, target=None)

The target of the ApprovalConditionClient must always be an ApprovalCondition instance.

approve() → Tuple[int, Any]

Approve the target condition.

reject() → Tuple[int, Any]

Reject the taret condition.

class concord.conditionals.client.ConditionalClient(actor=None, target=None)

ConditionalClient is largely used as an easy way to access all the specific conditionclients at once, but can also has some helper methods and one state change - add_condition_to_action.

get_condition_as_client(*, condition_type: str, pk: int) → concord.actions.client.BaseClient

Given a condition type and pk, gets that condition object and returns it wrapped in a client. Note: condition type MUST be capitalized to match the client name.

get_condition_class(*, condition_type)

Get condition class object given condition type.

get_condition_item(*, condition_pk, condition_type)

Get condition item given pk and type.

get_condition_item_given_action_and_source(*, action_pk: int, source_id: str) → django.db.models.base.Model

Given the action_pk and source_id corresponding to a condition item, get that item.

get_condition_item_on_community(*, action_pk: int, community_pk: int, leadership_type: str)

Get condition item on an action given the community & leadership type that triggered it.

get_condition_item_on_permission(*, action_pk: int, permission_pk: int)

Get condition item corresponding to a specific action and permission.

get_condition_items_for_action(*, action_pk)

Get all condition items set on an action.

get_or_create_condition_on_community(action, community, leadership_type)

Given an action and community & leadership type, if a condition item exists get it, otherwise create it.

get_or_create_condition_on_permission(action, permission)

Given an action and permission, if a condition item exists get it, otherwise create it.

get_possible_conditions()

Get all possible conditions.

set_condition_on_action(condition_type, condition_data=None, permission_pk=None, community_pk=None, leadership_type=None, permission_data=None)

This is almost always created as a mock to be used in a condition TemplateField. Typically when creating the mock we want to supply condition_type and condition_data but leave the rest to be supplied later. When the action is actually run, the target should always be an action!

trigger_condition_creation(*, action, permission=None, community=None, leadership_type=None)

Create a condition item given action and corresponding info about the condition that triggered it.

trigger_condition_creation_from_source_id(*, action, source_id)

Trigger condition creation given an action and the source_id that triggered it.

class concord.conditionals.client.ConsensusConditionClient(actor=None, target=None)

The target of the ConsensusConditionClient must always be a ConsensusCondition instance.

get_current_results() → Dict

Gets current results of vote condition.

resolve() → Tuple[int, Any]

Resolve consensus condition.

resolveable() → tuple

Returns True if condition is ready to resolve, or False if not. If not, returns time until it will be ready to resolve.

respond(*, response: str) → Tuple[int, Any]

Add response to consensus condition.

class concord.conditionals.client.VoteConditionClient(actor=None, target=None)

The target of the VoteConditionClient must always be a VoteCondition instance.

can_abstain() → bool

Returns True if users can abstain, otherwise False.

get_current_results() → Dict

Gets current results of vote condition.

publicize_votes() → bool

Returns True if condition is set to publicize votes, otherwise False.

vote(*, vote: str) → Tuple[int, Any]

Add vote to condition.