The code is now re-written so it works with new oTree (>2.5) and new Django Channels (2.x)/
How does this thing work:
- We create a standard oTree app (
ebayfolder) - We add its name to the
settings.pyas an oTree extension:
EXTENSION_APPS = ['ebay']-
In
ebayfolder we create another sub-folder namedotree_extensionsand we create two python files there:consumers.pyrouting.py
-
routingdefines what path the javascript on the page should 'knock to' to reach our python code (which is mostly located inconsumers.py) -
consumersdefine our logic: it contains one class calledEbayConsumer
The logic there is straightforward - as soon as someone connects, we get his/her group id, and player id and find these two objects on our database.
Then we add new connections to a special group that allows them to communicate in real time (in connect method).
receive method of EbayConsumer is executed every time we get a new message from the user. If it contains
bid_up command then we send the information that current bid is increased to the entire group.
In other words we just call a new_bid method below, that:
- updates a price for the group.
- updates an information about the winner
- Resets the counter till when the auction is over.
- Sends this whole package to all group members.
Filipp Chapkovski, Higher School of Economics, Moscow