#1
by
ileppane
I am using oTree Studio and noticed that live_method does not work anymore in my apps after the update in January. The error is with both the previous version and the new version of oTree.
Here's a minimum working example that is simplified from the auction example in the docs.
class Player(BasePlayer):
counter = models.IntegerField(initial=0)
def live_method(player: Player, data):
if data['send'] == 1:
player.counter += 1
response = {'val': 1}
return {player.id_in_group: response}
class MyPage(Page):
form_model = 'player'
live_method = 'live_method'
page_sequence = [MyPage]
On MyPage the content is:
---------------------------------------
<span id="test"></span><br>
<span id="test2"></span><br>
<button type="button" onclick="sendValue()">Send</button>
---------------------------------------
and JavaScript:
---------------------------------------
let test = document.getElementById('test');
let test2 = document.getElementById('test2');
function liveRecv(data) {
let val = data.val;
test.innerHTML = val;
test2.innerHTML = 'ok';
}
function sendValue() {
liveSend({'send': 1});
}
---------------------------------------
The strange thing in this example is that live_method does not seem to send anything back. Also, with the new version of oTree the player.counter in the live_method does not update either, while with the previous version it does update. Furthermore, the new oTree returns
TypeError: 'str' object is not callable
in the live_method.
#2
by
ileppane
In addition to these issues, I've found that edits to the CSS in Studio do not always show up in the downloaded otree zip file, although other edits do.
#3
by
Chris_oTree
Hi, you are right the live_method of oTree studio is not working with oTree 6. I recommend to stay on oTree 5 until I get that fixed. As for the CSS issue, do a full page reload (ctrl+F5) after downloading changes to the CSS.
#4
by
ileppane
Thanks Chris. I figured the css issue, but it is still weird that it emerges now, after not having any problems with css previously.
#5
by
Chris_oTree
I changed CSS to be a separate stylesheet file, rather than injected into the body of each page. That is actually more standard, since it can be cached for better performance (only caveat is that requires the full page reload). Anyway thank you for raising the issue and the feedback.