otree_redwood.models module¶
-
class
otree_redwood.models.Connection(*args, **kwargs)[source]¶ Bases:
django.db.models.base.ModelConnections 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.
-
exception
-
class
otree_redwood.models.DecisionGroup(*args, **kwargs)[source]¶ Bases:
otree_redwood.models.GroupDecisionGroup receives Events on the
decisionschannel, then broadcasts them back to all members of the group on thegroup_decisionschannel.-
group_decisions¶ group_decisionsholds a map from participant code to their current decision.
-
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.parentis aForwardManyToOneDescriptorinstance.
-
subperiod_group_decisions¶ subperiod_group_decisionsis a copy of the state ofgroup_decisionsat the end of each subperiod.
-
when_all_players_ready()[source]¶ Initializes decisions based on
player.initial_decision(). Ifnum_subperiodsis set, starts a timed task to run the sub-periods.
-
-
class
otree_redwood.models.Event(*args, **kwargs)[source]¶ Bases:
django.db.models.base.ModelEvent 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.
-
timestamp¶ Time the event was received or sent by the server.
-
value¶ Arbitrary Event payload.
-
exception
-
class
otree_redwood.models.Group(*args, **kwargs)[source]¶ Bases:
otree.models.group.BaseGroupGroup 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.
-
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.parentis aForwardManyToOneDescriptorinstance.
-