otree_mytips
                Differenze
Queste sono le differenze tra la revisione selezionata e la versione attuale della pagina.
| Entrambe le parti precedenti la revisioneRevisione precedenteProssima revisione | Revisione precedente | ||
| otree_mytips [2020/09/10 09:52] – using labels pietro | otree_mytips [2020/09/12 07:49] (versione attuale) – randomize order pietro | ||
|---|---|---|---|
| Linea 1: | Linea 1: | ||
| ====== My tips with oTree ====== | ====== My tips with oTree ====== | ||
| - | ==== Override oTree localization ==== | + | ===== Override oTree localization  | 
| **Problem: | **Problem: | ||
| Linea 15: | Linea 15: | ||
| That's it! The strings will be shown next time you start oTree - including in Heroku (remember to '' | That's it! The strings will be shown next time you start oTree - including in Heroku (remember to '' | ||
| - | ==== Using labels ==== | + | ===== Using labels  | 
| When a room is set up for participant labels, I should _not_ distribute the auto-generated links available under '' | When a room is set up for participant labels, I should _not_ distribute the auto-generated links available under '' | ||
| + | |||
| + | ===== Including a figure made with matplotlib ===== | ||
| + | |||
| + | < | ||
| + | from matplotlib import pyplot as plt | ||
| + | from io import BytesIO | ||
| + | from base64 import b64encode | ||
| + | import urllib | ||
| + | |||
| + | class MyPage(Page): | ||
| + |     def create_figure(self): | ||
| + |         plt.figure(figsize=(4, | ||
| + |         plt.plot(range(3), | ||
| + | |||
| + | fig = plt.gcf() | ||
| + |         buf = BytesIO()  | ||
| + |         fig.savefig(buf, | ||
| + | buf.seek(0) | ||
| + | |||
| + | string = b64encode(buf.read()) | ||
| + | |||
| + | return urllib.parse.quote(string) | ||
| + | |||
| + |     def vars_for_template(self): | ||
| + |         return {' | ||
| + | </ | ||
| + | |||
| + | ... and inside the template: | ||
| + | |||
| + | < | ||
| + | <img width=" | ||
| + | </ | ||
| + | |||
| + | ===== Randomize order of two activities inside a same page ===== | ||
| + | |||
| + | Create a Boolean variable '' | ||
| + | |||
| + | '' | ||
| + | |||
| + | < | ||
| + | [...] | ||
| + | |||
| + | {% block content %} | ||
| + | {% if swap %} | ||
| + | {% block a_1 %}{% endblock %} | ||
| + | {% block b_1 %}{% endblock %} | ||
| + | {% else %} | ||
| + | {% block a_2 %}{% endblock %} | ||
| + | {% block b_2 %}{% endblock %} | ||
| + | {% endif %} | ||
| + | </ | ||
| + | |||
| + | '' | ||
| + | |||
| + | < | ||
| + | {% extends " | ||
| + | {% load otree %} | ||
| + | |||
| + | |||
| + | {% block a_1 %}{% block a_2 %} | ||
| + | This is block a. | ||
| + | {% endblock %}{% endblock %} | ||
| + | |||
| + | {% block b_1 %}{% block b_2 %} | ||
| + | This is block b. | ||
| + | {% endblock %}{% endblock %} | ||
| + | </ | ||
otree_mytips.1599731521.txt.gz · Ultima modifica:  da pietro
                
                