otree_redwood.models module

class otree_redwood.models.Connection(*args, **kwargs)[source]

Bases: django.db.models.base.Model

Connections are created and deleted as Participants connect to a WebSocket.

exception DoesNotExist

Bases: django.core.exceptions.ObjectDoesNotExist

exception MultipleObjectsReturned

Bases: django.core.exceptions.MultipleObjectsReturned

id

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

objects = <django.db.models.manager.Manager object>
participant

Each Participant should have only one connection.

participant_id

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

class otree_redwood.models.DecisionGroup(*args, **kwargs)[source]

Bases: otree_redwood.models.Group

DecisionGroup receives Events on the decisions channel, then broadcasts them back to all members of the group on the group_decisions channel.

class Meta[source]

Bases: object

abstract = False
group_decisions

group_decisions holds a map from participant code to their current decision.

num_subperiods()[source]

Override to turn on sub-period behavior. None by default.

rate_limit()[source]

Override to turn on rate-limiting behavior. If used, the return value of rate_limit determines the minimum time between broadcasted ::attr::group_decisions updates.

session

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.

subperiod_group_decisions

subperiod_group_decisions is a copy of the state of group_decisions at the end of each subperiod.

when_all_players_ready()[source]

Initializes decisions based on player.initial_decision(). If num_subperiods is set, starts a timed task to run the sub-periods.

class otree_redwood.models.Event(*args, **kwargs)[source]

Bases: django.db.models.base.Model

Event stores a single message going in or out across a WebSocket connection.

exception DoesNotExist

Bases: django.core.exceptions.ObjectDoesNotExist

exception MultipleObjectsReturned

Bases: django.core.exceptions.MultipleObjectsReturned

channel

Channels act as tags to route Events.

content_type

Used to relate this Event to an arbitrary Group.

content_type_id

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_timestamp(**morekwargs)
get_previous_by_timestamp(**morekwargs)
group

The Group the event was sent to/from.

group_pk

Primary key of the Event’s related Group.

id

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

message

Dictionary representation of the Event appropriate for JSON-encoding.

objects = <django.db.models.manager.Manager object>
participant

The Participant who sent the event - null for server-sent events.

participant_id

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

save(*args, **kwargs)[source]

Saving an Event automatically sets the timestamp if not already set.

timestamp

Time the event was received or sent by the server.

value

Arbitrary Event payload.

class otree_redwood.models.Group(*args, **kwargs)[source]

Bases: otree.models.group.BaseGroup

Group is designed to be used instead of the oTree BaseGroup to provide Redwood-specific functions for coordinating inter-page communication for players in the Group.

class Meta[source]

Bases: object

abstract = False
period_length()[source]

Implement this to set a timeout on the page. A message will be sent on the period_start when all players in the group have connected their websockets. Another message will be send on the period_end channel period_length seconds from the period_start message.

ran_ready_function

Set when the when_all_players_ready() function has been run. Ensures run-only-once semantics.

save(*args, **kwargs)[source]

BUG: Django save-the-change, which all oTree models inherit from, doesn’t recognize changes to JSONField properties. So saving the model won’t trigger a database save. This is a hack, but fixes it so any JSONFields get updated every save. oTree uses a forked version of save-the-change so a good alternative might be to fix that to recognize JSONFields (diff them at save time, maybe?).

send(channel, payload)[source]

Send a message with the given payload on the given channel. Messages are broadcast to all players in the group.

session

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.

when_all_players_ready()[source]

Implement this to perform an action for the group once all players are ready.

when_player_disconnects(player)[source]

Implement this to perform an action when a player disconnects.

otree_redwood.models.fake_lock()[source]